mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
Using Object.create in Factory now
This commit is contained in:
parent
b02f169fc9
commit
c7898319c3
1 changed files with 19 additions and 14 deletions
|
|
@ -1,22 +1,27 @@
|
||||||
define(['Server/NotificationCenter'], function(NotificationCenter) {
|
define(['Server/NotificationCenter'], function(NotificationCenter) {
|
||||||
|
|
||||||
function Factory() {
|
function Factory() {
|
||||||
this.notificationCenter = new NotificationCenter();
|
this.notificationCenter = new NotificationCenter();
|
||||||
}
|
}
|
||||||
|
|
||||||
Factory.prototype.new = function () {
|
Factory.prototype.new = function (constructor /*, arg1, arg2, ... */) {
|
||||||
|
|
||||||
if (arguments.length < 1)
|
if (arguments.length < 1)
|
||||||
throw 'Too fiew arguments';
|
throw 'Too fiew arguments';
|
||||||
if (typeof arguments[0] != 'function')
|
if (typeof arguments[0] != 'function')
|
||||||
throw arguments[0] + ' is not a function';
|
throw arguments[0] + ' is not a function';
|
||||||
|
|
||||||
var type = arguments[0];
|
var instance = Object.create(constructor.prototype, {
|
||||||
var object = new (type.bind.apply(type,arguments))();
|
notificationCenter: {
|
||||||
object.notificationCenter = this.notificationCenter;
|
value: this.notificationCenter
|
||||||
object.factory = this;
|
},
|
||||||
return object;
|
factory: {
|
||||||
|
value: this
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
constructor.apply(instance, Array.prototype.slice.call(arguments, 1));
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Factory;
|
return Factory;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue