# Queuable Getter Setter.js
---
### like getter/setter but better
# Info
* repository on [github](https://github.com/jeromeetienne/queuablegettersetter.js)
* under [MIT license](http://jetienne.mit-license.org)
* written by [jerome etienne](http://jetienne.com)
# part of debug.js
* larger effort
* Let's make javascript easier to debug
### property getter setter
* used to intercept property access
* available in modern javascript
* Object.\_\_defineGetter\_\_
* Object.\_\_defineSetter\_\_
### Example of \_\_defineGetter\_\_
Before
```
var foo = {
bar : 1
};
console.log("bar", foo.bar);
// display in console "1"
```
After
```
foo.__defineGetter__('bar', function(){
return 2;
});
console.log("bar", foo.bar);
// display in console "2"
```
### Any issues ? NOT QUEUABLE
```
var foo = { bar : 1 };
foo.__defineGetter__('bar', function(){
console.log("blabla")
return 2;
});
foo.__defineGetter__('bar', function(){
return 3;
});
console.log("bar", foo.bar);
// display in console "3" and not "blabal"
```
* your can't chain multiple getter!
* same as in window.onLoad **vs** window.addEventListener('load', fn)
* always the same mistakes over and over /rants
## queuable getter setter
### to the rescue!!
### queuable getter setter
just add a 'Q'
```
// define the object as usual
var foo = {
bar : 32
};
// add a first getter which double the value
foo.__defineQGetter__('bar', function(value){
return value*2;
});
// add a second getter which add one to the value
foo.__defineQGetter__('bar', function(value){
return value+1;
});
// display the value of foo.bar
console.log( foo.bar )
// outputs "65" so they are queued! :)
```
Same for Object.\_\_defineQSetter\_\_
# Works EveryWhere
### Same Way in *browser* and *node.js*
## Works in node.js
Install
```
npm install queueablegettersetter.js
```
Test
```
$ make test
✓ Object.__defineQGetter__ is able to get without error: 0ms
✓ Object.__defineQSetter__ is able to set without error: 0ms
✓ Object.__defineQSetter__ is able to get without error: 0ms
✔ 3 tests complete (3 ms)
```
## Works in Browser
Install
```
```
Test
# The End
Questions ?
Tomatoes maybe ?