0.0.4 • Published 11 years ago

private.js v0.0.4

Weekly downloads
1
License
-
Repository
github
Last release
11 years ago

private.js Build Status

private.jsは任意のprefixが付与されたプロパティにプライベートアクセサを付与するライブラリです。 サバクラ両方で動く事を目標に開発しています。コードは非常にdirtyです。

Install

Node

and

Browser

Usage

関数Pvtの第一引数に渡したprefixが付与されたプロパティをprivateにします。

var Pvt = require("../lib/private"),
  expect = require("expect.js");

var klass = Pvt("_", {

  getPublicVariable: function() {
    return this.publicVariable;
  },

  getPrivatevariable: function() {
    return _privateVariable;
  },

  getPrivateMethodReferPrivateVariable: function() {
    return _getPrivateVariable();
  },

  // TODO not support yet
  getPrivateMethodReferPublicVariable: function() {
    return _getPublicVariable();
  },

  _getPrivateVariable: function() {
    return _privateVariable;
  },

  _getPublicVariable: function() {
    return this.publicVariable;
  },

  publicVariable: 1,

  _privateVariable: 2
});

describe('method suite', function() {
  it('getPublicVariable() should equal 1', function () {
    expect(klass.getPublicVariable()).to.equal(1);
  });

  it('getPrivatevariable() should equal 2', function () {
    expect(klass.getPrivatevariable()).to.equal(2);
  });

  it('getPrivateMethodReferPrivateVariable() should equal 2', function () {
    expect(klass.getPrivateMethodReferPrivateVariable()).to.equal(2);
  });

  it('should throw a error when access private method', function () {
    expect(function() {
      klass._getPrivateVariable();
      klass._getPublicVariable();
    }).to.throwError();
  });
});

describe('Variable suite', function() {
  it('publicVariable should equal 1', function () {
    expect(klass.publicVariable).to.equal(1);
  });

  it("can't access private variable", function () {
    expect(klass).to.not.have.property('_privateVariable');
    expect(klass._privateVariable).to.equal(undefined);
  });
});

Release note

  • 2013/04/22 0.0.1 release

TODO

  • privateメソッドがpublicプロパティにアクセスできない問題の修正.
0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago