mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
52 lines
No EOL
1 KiB
JavaScript
52 lines
No EOL
1 KiB
JavaScript
function Factory() {
|
|
this.notificationCenter = new NotificationCenter();
|
|
}
|
|
|
|
Factory.prototype.new = function () {
|
|
|
|
if (arguments.length < 1)
|
|
throw 'Too fiew arguments';
|
|
if (typeof arguments[0] != 'function')
|
|
throw arguments[0] + ' is not a function';
|
|
|
|
var module = arguments[0];
|
|
|
|
module.prototype = new ExtensibleObject({
|
|
factory: this,
|
|
notificationCenter: this.notificationCenter
|
|
});
|
|
|
|
return new (module.bind.apply(module, arguments))();
|
|
}
|
|
|
|
function ExtensibleObject(properties) {
|
|
for(var propertyName in properties) {
|
|
this[propertyName] = properties[propertyName];
|
|
}
|
|
}
|
|
|
|
function Player(name) {
|
|
this.name = name;
|
|
}
|
|
|
|
function NotificationCenter() {
|
|
this.foo = "a"
|
|
}
|
|
|
|
NotificationCenter.prototype.alert = function(a) {
|
|
console.log(a)
|
|
}
|
|
|
|
var factory = new Factory();
|
|
|
|
var player = factory.new(Player, "jeena");
|
|
|
|
player.factory.new(Player, "logsol").notificationCenter.alert("foo");
|
|
|
|
|
|
/*
|
|
|
|
Lala:chuck.js jeena$ node Factory.js
|
|
foo
|
|
|
|
*/ |