原型对象用字面量赋值时需要注意将constructor指回原对象。
<script>
function Person(name , age){
this.name = name ;
this.age = age ;
this.say = function (){
return "name : "+ this.name + "age: "+this.age ;
} ;
}
Person.prototype = {
address :"haerbin" ,
school:"哈工大"//,
//constructor:Person
}
var p = new Person("zhangsan" , 19) ;
console.log(p.constructor == Person) ;
</script>
如果不加入constructor:Person (强制指向),控制台会打印false。说明prototype的constructor指向了另外的一个Object对象。