问题描述
function Plant () {
this.country = "Mexico";
this.isOrganic = true;
}
Plant.prototype.showNameAndColor = function () {
console.log("I am a " + this.name + " and my color is " + this.color);
}
Plant.prototype.amIOrganic = function () {
if (this.isOrganic)
console.log("I am organic,Baby!");
}
上面的代码是否类似于下面的代码?
function Plant () {
this.country = "Mexico";
this.isOrganic = true;
this.showNameAndColor = function () {
console.log("I am a " + this.name + " and my color is " + this.color);
}
this.prototype.amIOrganic = function () {
if (this.isOrganic)
console.log("I am organic,Baby!");
}
}
* 1。上面的两个代码段是否完全相似?
- 在第一个代码段中,有两个函数
showNameAndClor
和amIOrganic
使用Plant.Prototype
进行设置,这意味着所有将继承Plant对象的新对象都可以访问这些函数除了其自身属性以外的两个功能?*
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)