private.js

0.0.4 • Public • Published

private.js Build Status

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.

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

Readme

Keywords

none

Package Sidebar

Install

npm i private.js

Weekly Downloads

1

Version

0.0.4

License

MIT

Last publish

Collaborators

  • hotchemi