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

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -