JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<p><strong>Console says:</strong></p>
<code id="console"></code>
</div>
JavaScript
var Private = new Class((function(){
var privscope = {};
var privID = 0;
var newPrivscope = function(obj){
privID++;
obj._privID = privID;
privscope[obj._privID]={};
privscope[obj._privID]['___privID']=obj._privID;
};
return {
getPrivate:function(id){
if(!this._privID){
newPrivscope(this);
}
if(privscope[this._privID]['___privID']!=this._privID){
console.log('privID manipulated');
}
return privscope[this.privID][id];
}.protect(),
setPrivate:function(id,value){
console.log(id);
if(!this._privID){
newPrivscope(this);
}
if(privscope[this._privID]['___privID']!=this._privID){
console.log('privID manipulated');
}
privscope[this._privID][id]=value;
}.protect(),
};
})());
var tPriv2 = new Class({
Implements:Private,
initialize: function(options){
this.setPrivate('test',1);
},
blub:function(){
return this.getPrivate('test');
},
blob:function(){
var j = this.getPrivate('test');
this.setPrivate(j+1);
},
});
var myTPriv = new tPriv2();
console.log(myTPriv);
var myTPriv2 = new tPriv2();
console.log(myTPriv2);
myTPriv2.blob();
console.log(myTPriv2);
console.log(myTPriv);