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?
巴扎黑2017-05-19 10:33:03
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.
迷茫2017-05-19 10:33:03
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