【发布时间】:2011-06-14 05:36:10
【问题描述】:
假设我有这样的课程:
function Widget() {
this.id = new Date().getTime();
// other fields
}
Widget.prototype = {
load: function(args) {
// do something
}
}
从这个类中,我创建了一些其他类,它们继承了相同的原型,但添加了一些方法。我想要做的是能够在子类中定义一个 load() 方法,它首先调用父方法,然后执行一些代码。比如:
SpecialWidget.prototype = {
load: function(args) {
super.load(args);
// specific code here
}
}
我知道 Javascript 中没有 super 关键字,但一定有办法做到这一点。
【问题讨论】:
标签: javascript inheritance prototype