首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

call兑现重载函数后的调用

2012-08-08 
call实现重载函数后的调用function Parent() {this.Method function() {alert(Parent Method)}}fun

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/

热点排行