getter-setter

set and get decoration for js objects

npm install getter-setter
8 downloads in the last week
32 downloads in the last month

getter-setter

Build Status

Install

npm install getter-setter

2 methods for decorating objects with getters and setters:

  1. .node(obj) proto method only works in node.js or v8 browsers such as chrome

     var obj = require('getter-setter').node({hello: 'world'});
     obj.get('hello');
    
  2. .browser(obj) underscore extend method (works in all browsers as well as node.js)

     var obj = require('getter-setter').browser({hello: 'world'});
     obj.get('hello');
    

Full Example

var decorate = require('getter-setter').browser,
    obj = decorate({
        hello: 'world'
    });

// outputs "world"
console.log(obj.get('hello'));

// outputs "bye"
console.log(obj.set('hello', 'bye'));
console.log(obj.get('hello'));
npm loves you