mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
changed to extnsible object
This commit is contained in:
parent
32ccedf4a3
commit
df6c8bf0e2
1 changed files with 23 additions and 7 deletions
30
Factory.js
30
Factory.js
|
|
@ -9,19 +9,30 @@ Factory.prototype.new = function () {
|
||||||
if (typeof arguments[0] != 'function')
|
if (typeof arguments[0] != 'function')
|
||||||
throw arguments[0] + ' is not a function';
|
throw arguments[0] + ' is not a function';
|
||||||
|
|
||||||
var klass = arguments[0];
|
var module = arguments[0];
|
||||||
klass.prototype = new ChuckObject(this.notificationCenter, this);
|
module.prototype = new ExtensibleObject({
|
||||||
return new (klass.bind.apply(klass,arguments))();
|
notificationCenter: this.notificationCenter,
|
||||||
|
factory: this
|
||||||
|
});
|
||||||
|
|
||||||
|
return new (module.bind.apply(module, arguments))();
|
||||||
}
|
}
|
||||||
|
|
||||||
function ChuckObject(notificationCenter, factory) {
|
function ExtensibleObject(properties) {
|
||||||
this.notificationCenter = notificationCenter;
|
for(var propertyName in properties) {
|
||||||
this.factory = factory;
|
this.__defineGetter__(propertyName, function() {
|
||||||
|
return properties[propertyName]
|
||||||
|
});
|
||||||
|
|
||||||
|
this.__defineSetter__(propertyName, function(val) {
|
||||||
|
properties[propertyName] = val;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Player(name) {
|
function Player(name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
console.log("Created Player");
|
console.log("Created Player: " + name);
|
||||||
console.log("Player.notificationCenter " + this.notificationCenter);
|
console.log("Player.notificationCenter " + this.notificationCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,10 +40,15 @@ function NotificationCenter() {
|
||||||
console.log("Created NotificationCenter");
|
console.log("Created NotificationCenter");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotificationCenter.prototype.alert = function(a) {
|
||||||
|
console.log(a)
|
||||||
|
}
|
||||||
|
|
||||||
var factory = new Factory();
|
var factory = new Factory();
|
||||||
|
|
||||||
var player = factory.new(Player, "jeena");
|
var player = factory.new(Player, "jeena");
|
||||||
console.log("Player.name " + player.name);
|
console.log("Player.name " + player.name);
|
||||||
|
console.log("New player name: " + player.factory.new(Player, "logsol").notificationCenter.alert);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue