js.private
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "js.private", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Private properties for objects", | ||
@@ -16,4 +16,4 @@ "main": "./dst/Private.js", | ||
"dependencies": { | ||
"js.clone": "^0.0.1" | ||
"js.clone": ">0.0.1" | ||
} | ||
} |
@@ -25,7 +25,2 @@ ### Install | ||
remove(){ | ||
$.destroy( this ); // destroy private props to free memory | ||
console.log( "i removed" ); | ||
} | ||
} | ||
@@ -49,4 +44,3 @@ | ||
man.generateInfo // > undefined | ||
man.remove() // > "I removed" | ||
``` | ||
@@ -7,13 +7,9 @@ import Clone from "js.clone"; | ||
constructor( props ){ | ||
this.props = props; | ||
this.owners = []; | ||
this.values = []; | ||
this.get = this.get.bind( this ); | ||
this.get.destroy = this.destroy.bind( this ); | ||
this.props = props; | ||
this.key = Math.random().toString( 36 ).replace( /^.{2}/, "_private_" ); | ||
this.get = this.get.bind( this ); | ||
} | ||
get( context ){ | ||
let key = this.owners.indexOf( context ); | ||
if( key < 0 ) key = this.set( context ); | ||
return this.values[ key ]; | ||
return context[ this.key ] || this.set( context ); | ||
} | ||
@@ -26,11 +22,5 @@ | ||
clone[ attr ] = clone[ attr ].bind( context ); | ||
this.owners.push( context ); | ||
return this.values.push( clone ) - 1; | ||
return context[ this.key ] = clone; | ||
} | ||
destroy( context ){ | ||
let key = this.owners.indexOf( context ); | ||
return delete this.owners[ key ] && delete this.values[ key ]; | ||
} | ||
} | ||
@@ -37,0 +27,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4233
76
45
+ Addedjs.clone@0.0.3(transitive)
- Removedjs.clone@0.0.1(transitive)
Updatedjs.clone@>0.0.1