From 976bf12cbe8335c8db9c2589761172a96841a7f7 Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Thu, 19 Jul 2012 16:24:23 +0200 Subject: [PATCH] working example with ExtensibleObject --- Factory.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Factory.js b/Factory.js index 18e9819..f011a8b 100644 --- a/Factory.js +++ b/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"); /*