Decorate JavaScript objects with getters and setters
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

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'));