读书人

call兑现重载函数后的调用

发布时间: 2012-08-08 14:32:45 作者: rapoo

call实现重载函数后的调用
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

热点推荐