javascript - js construction object problem
習慣沉默
習慣沉默 2017-05-19 10:31:03
0
2
549
function Person {}
Person.prototype.test = function() {
} 

new Person()

new Person

These two writing methods have the same effect. Why does not adding parentheses have the same effect as the previous one?

習慣沉默
習慣沉默

reply all(2)
巴扎黑
new constructor[([arguments])]

When the code new Person(...) is executed:

A new object is created. It inherits from Person.prototype.
Constructor Person is executed. When executing, the corresponding parameters will be passed in, and the context (this) will be designated as this new instance.

new Person is equivalent to new Person(), and can only be used without passing any parameters.


迷茫

Is there any problem? By default, no value is passed when parentheses are not added

function Person(val){this.val=val};//类似这种传值的就得加

And the priorities of adding () and not adding are also different

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