2

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 ?

jsbin

2 Answers 2

3

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 call Function(…) is equivalent to the object creation expression new Function(…) with the same arguments.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you and sorry for not finding it myself.(searched though)
1

Both are same.

But if you use new, every property inside the object will have a new instance.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.