From 8425831450b5756d569777dbb2977bb91ec62664 Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Thu, 19 Jul 2012 15:38:17 +0200 Subject: [PATCH] changed to Object.create --- Factory.js | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/Factory.js b/Factory.js index 08acac4..9b34132 100644 --- a/Factory.js +++ b/Factory.js @@ -10,34 +10,22 @@ Factory.prototype.new = function () { throw arguments[0] + ' is not a function'; var module = arguments[0]; - module.prototype = new ExtensibleObject({ - notificationCenter: this.notificationCenter, - factory: this - }); - return new (module.bind.apply(module, arguments))(); -} - -function ExtensibleObject(properties) { - for(var propertyName in properties) { - this.__defineGetter__(propertyName, function() { - return properties[propertyName] - }); - - this.__defineSetter__(propertyName, function(val) { - properties[propertyName] = val; - }); - } + return Object.create( + module.prototype, + { + factory: {value: this}, + notificationCenter: {value: this.notificationCenter} + } + ); } function Player(name) { this.name = name; - console.log("Created Player: " + name); - console.log("Player.notificationCenter " + this.notificationCenter); } function NotificationCenter() { - console.log("Created NotificationCenter"); + this.foo = "a" } NotificationCenter.prototype.alert = function(a) { @@ -47,8 +35,7 @@ NotificationCenter.prototype.alert = function(a) { var factory = new Factory(); var player = factory.new(Player, "jeena"); -console.log("Player.name " + player.name); -console.log("New player name: " + player.factory.new(Player, "logsol").notificationCenter.alert); +console.log(player.notificationCenter); /*