Code:
1)
function Person(name,age){
this.name=name;
this.age=age;
}
var p=new Person('stack',100);
console.dir(p);
console.info(p.name);//'stack'.
But I wonder why I can create a new person use:
var p2=new Person(); //no error
There is not a constructor like:
function Person(){}
why?
2)
function Person(name,age){
var _name,_age;
this._name=name;
this._age=age;
}
var p=new Person('stack',100);
console.dir(p);
What's the difference between this and the 1)'s manner?