New MyFunction () versus New (MyFunction)

I go through the vow documentation and use syntax in several places

var myVar = new(MyFunction);

eg.

var promise = new(events.EventEmitter);

I am familiar with new MyFunction()and new MyFunction(and yes, I read this question ). But the syntax above is, well, new to me - it looks like a function call, although I suspect it's just new MyFunctionwith some brackets added. Is there any difference between these uses new? If not, is there a good argument for using one or the other? I would have thought that I new MyFunction()was the most discriminating.

Sorry if this is a duplicate - I searched, but could not find it.

+5
source share
3 answers

, , , (). :

function Foo() { this.now = new Date(); }
var f1 = new Foo;
var f2 = (new Foo);
var f3 = new(Foo);
var f4 = new Foo();
var f5 = (new Foo());

, , Foo (- parens), (undefined), "" ( "undefined" ):

var x = new(Foo()); // TypeError: undefined is not a function
+4

var MyFunction = function(){
    alert("ok");
}

var myVar = new(MyFunction);

var myVar = new(function(){
    alert("ok");
});

.

+4

, , , : new . :

if (typeof(myvar) === "function")

:

return(myvar);

- , . , .

+3

All Articles