大神看下代码问题,为什么弹不出对话框!!

J i f f 2019-08-13 02:27:30
function inheritPrototype(sub, superType) {
var prototype = Object.create(superType.prototype);
prototype.constructor = sub;
sub.prototype = prototype
}

function superType(name) {
this.name = name;
this.colors = ['red', 'green']
}
superType.prototype.sayname = function() {
alert(this.name)
}

function sub(name, age) {
superType.call(this, name);
this.age = age
}
inheritPrototype(sub, superType);
sub.prototype.sayage = function() {
alert(this.age)
}
sub.prototype = new superType();
var instance = new sub("wong", 29)
...全文
68 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
J i f f 2019-08-13
  • 打赏
  • 举报
回复
引用 2 楼 追热 的回复:
sayage的位置调到sub.prototype = new superType();后面,放在前面会被替换掉所以sayage无效
是自己傻吊了
J i f f 2019-08-13
  • 打赏
  • 举报
回复
引用 2 楼 追热 的回复:
sayage的位置调到sub.prototype = new superType();后面,放在前面会被替换掉所以sayage无效
JS高级程序设计这本书是这么写的0.0
追热 2019-08-13
  • 打赏
  • 举报
回复
sayage的位置调到sub.prototype = new superType();后面,放在前面会被替换掉所以sayage无效
2019-08-13
  • 打赏
  • 举报
回复

instance.sayname();
你没调用

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧