执行以下程序,输出结果为()
function Person(age){
this.age = age;
}
Person.prototype = {
constructor:Person,
getAge:function(){
console.log(this.age);
},
}
var ldh = new Person(24);
Person.prototype.age = 18;
Object.prototype.age = 20;
ldh.getAge();
function Person(age) { this.age = age; } Person.prototype = { constructor: Person, getAge: function () { console.log(this.age); }, } var ldh = new Person(24); //ldh = { age: 24 } Person.prototype.age = 18; // Person.prototype = { // age: 18 , // getAge: function () { // console.log(this.age); // }, //} Object.prototype.age = 20; // Object.prototype = { age: 20 } ldh.getAge(); //ldh这个对象上没有getAge方法,就去构造函数的原型上找 //继承构造函数的原型上的getAge这个方法,this指向的是实例化对象ldh