function Person(name,age,gender){this
this.name=name;對象
this.age=age;事件
this.gender=gender;string
}io
//建立一個Person實例function
var per = new Person("張三",24,"男");方法
//當咱們直接在頁面中打印一個對象時,事件是輸出的對象的tostring()方法的返回值new
若是咱們但願在輸出對象時不輸出[objec objec],能夠爲對象添加一個tostring()方法return
var result = per.tostring();實例
per.toString =function(){
return"Person(name="+this.name+",age="+this.age+",gender="+this.gender+")"
}