diff --git a/lib/Server/Factory.js b/lib/Server/Factory.js index e83252b..36ebc84 100644 --- a/lib/Server/Factory.js +++ b/lib/Server/Factory.js @@ -1,22 +1,27 @@ define(['Server/NotificationCenter'], function(NotificationCenter) { function Factory() { - this.notificationCenter = new NotificationCenter(); + 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 type = arguments[0]; - var object = new (type.bind.apply(type,arguments))(); - object.notificationCenter = this.notificationCenter; - object.factory = this; - return object; - + Factory.prototype.new = function (constructor /*, arg1, arg2, ... */) { + + if (arguments.length < 1) + throw 'Too fiew arguments'; + if (typeof arguments[0] != 'function') + throw arguments[0] + ' is not a function'; + + var instance = Object.create(constructor.prototype, { + notificationCenter: { + value: this.notificationCenter + }, + factory: { + value: this + } + }); + + constructor.apply(instance, Array.prototype.slice.call(arguments, 1)); + return instance; } return Factory;