Reputation: 148524
How should I initialize Function constructor
function :
(both seems to work.)
like this :
var t= new Function ("a","alert(a)");
t(3)//3
alert(Object.prototype.toString.apply(t)); //[object Function]
or
var t= Function ("a","alert(a)"); //without new
t(3) //3
alert(Object.prototype.toString.apply(t));//[object Function]
Is there any difference ?
Upvotes: 2
Views: 66
Reputation: 13151
Both are same.
But if you use new, every property inside the object will have a new instance.
Upvotes: 1
Reputation: 165941
They are identical. From the spec:
When
Function
is called as a function rather than as a constructor, it creates and initialises a new Function object. Thus the function callFunction(…)
is equivalent to the object creation expression newFunction(…)
with the same arguments.
Upvotes: 3