Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hotchemi/private.js
Provides private accessor to javascript object.
https://github.com/hotchemi/private.js
Last synced: 3 months ago
JSON representation
Provides private accessor to javascript object.
- Host: GitHub
- URL: https://github.com/hotchemi/private.js
- Owner: hotchemi
- License: mit
- Created: 2013-04-13T03:57:37.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-02-01T20:05:54.000Z (almost 11 years ago)
- Last Synced: 2024-09-24T10:12:03.718Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 187 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
private.js [![Build Status](https://secure.travis-ci.org/hotchemi/private.js.png)](http://travis-ci.org/hotchemi/private.js)
==========
private.js provides private accessor to object property with option prefix.## Install
### Node
$ npm install private.js### Browser
<script src="private.min.js"></script>## Usage
Node.js sample.
```javascript
var $pvt = require("private.js"),
expect = require("expect.js");var klass = $pvt("_" /* prefix */, {
// public method access to public variable
getPublicVariable: function() {
return this.publicVariable;
},// public method access to private variable
getPrivatevariable: function() {
return _privateVariable;
},// privateメンバを参照しているprivateメソッドを呼び出すpublic method
getPrivateMethodReferPrivateVariable: function() {
return _getPrivateVariable();
},// publicメンバを参照しているprivateメソッドを呼び出すpublic method
getPrivateMethodReferPublicVariable: function() {
// この場合はコンテキストを指定しないといけない…
return _getPublicVariable.call(this);
},// privateメンバにアクセスするprivate method
_getPrivateVariable: function() {
return _privateVariable;
},// publicメンバにアクセスするprivate method
_getPublicVariable: function() {
return this.publicVariable;
},// public variable
publicVariable: 1,// private variable
_privateVariable: 2
});
```
## Test
$ npm test## Minify
$ grunt## Release note
* 2013/04/22 0.0.1 release
* 2013/04/24 0.0.4 release