added inheritance test

This commit is contained in:
Jeena Paradies 2012-07-19 14:06:41 +02:00
parent d679d61b64
commit 32ccedf4a3

46
Factory.js Normal file
View file

@ -0,0 +1,46 @@
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 klass = arguments[0];
klass.prototype = new ChuckObject(this.notificationCenter, this);
return new (klass.bind.apply(klass,arguments))();
}
function ChuckObject(notificationCenter, factory) {
this.notificationCenter = notificationCenter;
this.factory = factory;
}
function Player(name) {
this.name = name;
console.log("Created Player");
console.log("Player.notificationCenter " + this.notificationCenter);
}
function NotificationCenter() {
console.log("Created NotificationCenter");
}
var factory = new Factory();
var player = factory.new(Player, "jeena");
console.log("Player.name " + player.name);
/*
Lala:chuck.js jeena$ node Factory.js
Created NotificationCenter
Created Player
Player.notificationCenter [object Object]
Player.name jeena
*/