【发布时间】:2015-03-11 17:30:00
【问题描述】:
我是 OOPS JavaScript 的新手。清楚。在此处查看我的 JavaScript 代码,
function a(){
this.first = "Kar";
}
function b(){
this.last = "Sho";
}
function c(){
this.getName = function(){
return this.first+this.last;
}
}
c.prototype.u = new a();
c.prototype.v = new b();
var d = new c();
alert(d.getName());
在这里,我得到以下输出,
NaN
但我想打印 KarSho。问题出在哪里?
我知道以下方法,
b.prototype = new a();
c.prototype = new b();
其实我想要的是,在c中调用a和b即可。就是这样。
【问题讨论】:
标签: javascript oop inheritance prototype