mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
49 lines
No EOL
942 B
JavaScript
49 lines
No EOL
942 B
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];
|
|
|
|
return Object.create(
|
|
module.prototype,
|
|
{
|
|
factory: {value: this},
|
|
notificationCenter: {value: this.notificationCenter}
|
|
}
|
|
);
|
|
}
|
|
|
|
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");
|
|
console.log(player.notificationCenter);
|
|
|
|
|
|
/*
|
|
|
|
Lala:chuck.js jeena$ node Factory.js
|
|
Created NotificationCenter
|
|
Created Player
|
|
Player.notificationCenter [object Object]
|
|
Player.name jeena
|
|
|
|
*/ |