javascript - Cannot create Object of function defined in closure? -
Why is it that I can not create objects from a function defined in the closing?
var external = function () {var constructor = function () {this.foo = 1; }; Return constructor; }; // should be: {foo: 1}, but it is: undefined var constructorObject = new external () (); // This works var c = external (); Var Constructor Object = New C ();
The external function call in the bracket needs to be wrapped evenly:
var constructorObject = new (outer ()) (); // ^ ^ Center Center here console.log (Constructor object); // constructor {foo: 1} console.log (constructor object.fu); // 1
Comments
Post a Comment