Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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