javascript - js object-oriented
扔个三星炸死你
扔个三星炸死你 2017-06-26 10:58:46
0
4
618

Excuse me, what is the difference between adding or not adding parentheses to the mm function after new? Why do I get the same results?
Please ask a senior expert to explain the principle inside.

扔个三星炸死你
扔个三星炸死你

reply all(4)
大家讲道理

First of all, for this kind of basic question, you need to learn to consult the official documentation.
The documentation has detailed instructions: new foo is equivalent to new foo(), which can only be used without passing any parameters.
Of course, you can’t completely trust the documentation. , after all, the pitfalls of js. .
Then what’s the difference? There are detailed descriptions in this
priority summary: new (with parameter list) has a priority of 19, and new (without parameter separation) has a priority of 18, so new foo() will be executed first

Finally, I remember seeing an article not long ago about a disgusting interview question, which was: new f(), new f, new f.g(), new f().g(), etc. Regarding the priority calculation problem, you can search it yourself

phpcn_u1582

Refer to MDN

new constructor[([arguments])]

When there is no need to pass parameters, the brackets () are optional

洪涛

var mm = function(val){

this.m = val

}
var a = new mm(1) ;
console.log(a)
var b = new mm ;
console.log(b)

过去多啦不再A梦

If the constructor does not require parameters, there is no difference between adding and not adding parentheses.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template