. .
var - . .
: .
var testObj = (function() {
var data = {__proto__:null};
return new Class({
get: function(key) {
return data[this.uid][key] || null;
},
set: function(key, value) {
data[this.uid][key] = value;
},
remove: function(key) {
delete data[this.uid][key];
},
otherMethod: function() {
alert(this.get("foo"));
},
initialize: function() {
this.uid = String.uniqueID();
data[this.uid] = {};
}
});
})();
var foo = new testObj();
var bar = new testObj();
foo.set("bar", "banana");
console.log(foo.get("bar"));
console.log(bar.get("bar"));
bar.set("bar", "apple");
console.info(foo.get("bar"), bar.get("bar"));
: http://jsfiddle.net/dimitar/dCqR7/1/
, , this.
, :
http://jsfiddle.net/dimitar/dCqR7/2/
var testObj = (function() {
var data = {__proto__:null};
return new Class({
get: function(key) {
return data[key] || null;
},
set: function(key, value) {
data[key] = value;
},
remove: function(key) {
delete data[key];
},
otherMethod: function() {
alert(this.get("foo"));
}
});
});
var foo = new new testObj();
var bar = new new testObj();
foo.set("bar", "banana");
console.log(foo.get("bar"));
console.log(bar.get("bar"));
bar.set("bar", "apple");
console.info(foo.get("bar"), bar.get("bar"));
, ...
mootools , js , , , ..
, , data - . "" , data .
, , . Class... new Class({}); new new <var>() .
, , , - , , :
new (new Class({
initialize: function() {
alert("hi");
}
}))();
, , ( ):
var foo = new Class({
initialize: function() {
alert("hi");
}
});
new foo();
, , , ...