Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/techjacker/getter-setter
Decorate JavaScript objects with getters and setters
https://github.com/techjacker/getter-setter
Last synced: 15 days ago
JSON representation
Decorate JavaScript objects with getters and setters
- Host: GitHub
- URL: https://github.com/techjacker/getter-setter
- Owner: techjacker
- License: mit
- Created: 2013-04-16T14:10:29.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-06-05T11:58:37.000Z (over 11 years ago)
- Last Synced: 2024-08-09T03:02:01.784Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 609 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# getter-setter
[![Build Status](https://secure.travis-ci.org/techjacker/getter-setter.png)](http://travis-ci.org/techjacker/getter-setter)
### Install
```Shell
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```JavaScript
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)```JavaScript
var obj = require('getter-setter').browser({hello: 'world'});
obj.get('hello');
```## Full Example
```JavaScript
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'));
```