mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
changed to Object.create
This commit is contained in:
parent
df6c8bf0e2
commit
8425831450
1 changed files with 9 additions and 22 deletions
29
Factory.js
29
Factory.js
|
|
@ -10,34 +10,22 @@ Factory.prototype.new = function () {
|
||||||
throw arguments[0] + ' is not a function';
|
throw arguments[0] + ' is not a function';
|
||||||
|
|
||||||
var module = arguments[0];
|
var module = arguments[0];
|
||||||
module.prototype = new ExtensibleObject({
|
|
||||||
notificationCenter: this.notificationCenter,
|
|
||||||
factory: this
|
|
||||||
});
|
|
||||||
|
|
||||||
return new (module.bind.apply(module, arguments))();
|
return Object.create(
|
||||||
}
|
module.prototype,
|
||||||
|
{
|
||||||
function ExtensibleObject(properties) {
|
factory: {value: this},
|
||||||
for(var propertyName in properties) {
|
notificationCenter: {value: this.notificationCenter}
|
||||||
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: " + name);
|
|
||||||
console.log("Player.notificationCenter " + this.notificationCenter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function NotificationCenter() {
|
function NotificationCenter() {
|
||||||
console.log("Created NotificationCenter");
|
this.foo = "a"
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationCenter.prototype.alert = function(a) {
|
NotificationCenter.prototype.alert = function(a) {
|
||||||
|
|
@ -47,8 +35,7 @@ NotificationCenter.prototype.alert = function(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.notificationCenter);
|
||||||
console.log("New player name: " + player.factory.new(Player, "logsol").notificationCenter.alert);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue