What is return new function(); in JavaScript?
This question already has an answer here:
When we call a function with the new keyword. the following will happen:
new
object will be created in the memory So in essence, that is how you create instances in JavaScript. You need to call a function with the new keyword. When doing so, the function is called constructor.
In your example, the q
function returns an instance of the doStuff
method. Bare in mind though that the naming convention is not correct.
Constructors should be nouns rather that verbs and they should be in Pascal-case, not camel-case
链接地址: http://www.djcxy.com/p/40852.html