function Person(name){ this.name=name;
}
Person.prototype.getName=function(){return this.name;
}//調(diào)用函數(shù)var person=new Person("Nicholas");
alert(person.getName());疑問:同一個函數(shù),為啥在去掉this(原型模式中的this)后代碼如下:Person.prototype.getName=function(){ return name;
}出現(xiàn)如下的錯誤:Test3.html:102 Uncaught ReferenceError: age is not definedthis不去掉的話,就會輸出Nicholas;
JavaScript中去掉原型模式中this的疑問??
素胚勾勒不出你
2018-10-17 13:15:27