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

js.private

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js.private - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

36

dst/Private.js

@@ -21,10 +21,24 @@ "use strict";

this.props = props;
this.key = "_" + Math.random().toString(36).substr(2, 7) + "_";
this._key_ = "_" + Math.random().toString(36).substr(2, 7) + "_";
this._props_ = this.prepare(props);
}
_createClass(Private, [{
key: "prepare",
value: function prepare(props) {
for (var attr in props) {
if (props.hasOwnProperty(attr) && typeof props[attr] === "function") props[attr] = this.bind(this._key_, props[attr]);
}return props;
}
}, {
key: "bind",
value: function bind(key, method) {
return function () {
return method.apply(this[key], arguments);
};
}
}, {
key: "get",
value: function get(context) {
return context[this.key] || this.set(context);
return context[this._key_] || this.set(context);
}

@@ -34,14 +48,8 @@ }, {

value: function set(context) {
var clone = (0, _jsClone2["default"])(this.props);
for (var attr in clone) {
if (clone.hasOwnProperty(attr) && clone[attr] instanceof Function) clone[attr] = this.bind(clone[attr], context);
}return context[this.key] = clone;
var props = Object.create(this._props_);
for (var attr in this._props_) {
if (this._props_.hasOwnProperty(attr) && typeof this._props_[attr] === "object") props[attr] = (0, _jsClone2["default"])(this._props_[attr]);
}props[this._key_] = context;
return context[this._key_] = props;
}
}, {
key: "bind",
value: function bind(method, context) {
return function () {
return method.apply(context, arguments);
};
}
}]);

@@ -48,0 +56,0 @@

{
"name": "js.private",
"version": "0.1.0",
"version": "0.2.0",
"description": "Private properties for objects",

@@ -5,0 +5,0 @@ "main": "./dst/Private.js",

@@ -7,24 +7,32 @@ import Clone from "js.clone";

constructor( props ){
this.props = props;
this.key = `_${ Math.random().toString( 36 ).substr( 2, 7 ) }_`;
this._key_ = `_${ Math.random().toString( 36 ).substr( 2, 7 ) }_`;
this._props_ = this.prepare( props );
}
prepare( props ){
for( let attr in props )
if( props.hasOwnProperty( attr ) && typeof props[ attr ] === `function` )
props[ attr ] = this.bind( this._key_, props[ attr ] );
return props;
}
bind( key, method ){
return function(){
return method.apply( this[ key ], arguments );
};
}
get( context ){
return context[ this.key ] || this.set( context );
return context[ this._key_ ] || this.set( context );
}
set( context ){
let clone = Clone( this.props );
for( let attr in clone )
if( clone.hasOwnProperty( attr ) && clone[ attr ] instanceof Function )
clone[ attr ] = this.bind( clone[ attr ], context );
return context[ this.key ] = clone;
let props = Object.create( this._props_ )
for( let attr in this._props_ )
if( this._props_.hasOwnProperty( attr ) && typeof this._props_[ attr ] === `object` )
props[ attr ] = Clone( this._props_[ attr ] );
props[ this._key_ ] = context;
return context[ this._key_ ] = props;
}
bind( method, context ){
return function(){
return method.apply( context, arguments );
};
}
}

@@ -38,2 +46,2 @@

};
}
}
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