Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

private.js

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

private.js

provides private accessor to javascript object

  • 0.0.4
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 24 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc