Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/azproduction/privatize
Marks object properties as private
https://github.com/azproduction/privatize
Last synced: 22 days ago
JSON representation
Marks object properties as private
- Host: GitHub
- URL: https://github.com/azproduction/privatize
- Owner: azproduction
- License: mit
- Created: 2014-12-09T16:38:37.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2014-12-09T16:39:14.000Z (almost 10 years ago)
- Last Synced: 2024-10-12T15:54:19.335Z (about 1 month ago)
- Language: JavaScript
- Size: 113 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# privatize
[![NPM Version](https://badge.fury.io/js/privatize.png)]
(https://npmjs.org/package/privatize)[![Build Status](https://travis-ci.org/azproduction/privatize.png?branch=master)]
(https://travis-ci.org/azproduction/privatize)Marks object properties as private. JFYI this module requires ES5 features.
## Example
```js
var privatize = require('privatize');function A() {
this.value = 123;
setTimeout(function () {
this.set(134); // Works
}.bind(this), 1000);
return privatize(this, 'set');
}A.prototype = {
set: function (value) {
this.value = value;
},
get: function () {
return this.value;
}
};var a = new A();
console.log(a.get()); // Works
a.set(111); // Error (Property is private)
a.set; // Error (Property is private)
```# Backbone example
```js
var privatize = require('privatize'),
Model = require('backbone').Model;// Privatize all "write" methods
module.exports = privatize(new Model(), 'sync', 'set', 'fetch', 'attributes', 'clear', 'unset', 'save', 'destroy');
```