读书人

call实现override函数的调用有关问题

发布时间: 2012-08-15 16:57:17 作者: rapoo

call实现override函数的调用问题
function Parent() {
this.Method = function() {
alert("Parent Method");
};
};

function Son() {
Parent.call(this);

this.Method = function() {
alert("Son Method");
(new Parent()).Method.call(this);
};
};

function Grandson() {
Son.call(this);
this.Method = function(){
alert("Grandson Method");
(new Son()).Method.call(this);
};
};
调用 Son的method是成功的,
var s = new Son();
s.Method();
调用 Grandson的Method的失败,
var g = new Grandson();
g.Method();

[解决办法]
没有问题啊
[解决办法]
http://jsfiddle.net/3tn9J/

读书人网 >JavaScript

热点推荐