mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
working example with ExtensibleObject
This commit is contained in:
parent
3ee7c197f9
commit
976bf12cbe
1 changed files with 11 additions and 5 deletions
16
Factory.js
16
Factory.js
|
|
@ -11,12 +11,18 @@ Factory.prototype.new = function () {
|
|||
|
||||
var module = arguments[0];
|
||||
|
||||
var o = Object.create(module.prototype, {
|
||||
factory: {value: this},
|
||||
notificationCenter: {value: this.notificationCenter}
|
||||
module.prototype = new ExtensibleObject({
|
||||
factory: this,
|
||||
notificationCenter: this.notificationCenter
|
||||
});
|
||||
|
||||
return new (o.call(arguments))();
|
||||
return new (module.bind.apply(module, arguments))();
|
||||
}
|
||||
|
||||
function ExtensibleObject(properties) {
|
||||
for(var propertyName in properties) {
|
||||
this[propertyName] = properties[propertyName];
|
||||
}
|
||||
}
|
||||
|
||||
function Player(name) {
|
||||
|
|
@ -35,7 +41,7 @@ var factory = new Factory();
|
|||
|
||||
var player = factory.new(Player, "jeena");
|
||||
|
||||
player.factory.new(Player, "logsol").name;
|
||||
player.factory.new(Player, "logsol").notificationCenter.alert("foo");
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue