Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 原型链:call";超级";多层次方法_Javascript_Oop_Chaining_Prototype Chain - Fatal编程技术网

Javascript 原型链:call";超级";多层次方法

Javascript 原型链:call";超级";多层次方法,javascript,oop,chaining,prototype-chain,Javascript,Oop,Chaining,Prototype Chain,我有以下原型链 超超类 超类 阶级 每个都有一个名为do的方法 调用相应的超类方法的常用方法是什么? 目前我使用的是.prototype.\uuuuuuuuuuuuuu..调用(this),但这看起来很奇怪 控制台使用以下代码打印(如预期的那样): Class.prototype.do 超类.prototype.do SuperSuperClass.prototype.do 调用相应的超类方法的常用方法是什么 使用.prototype..call(this)。它不仅更短,而且还

我有以下原型链

  • 超超类
    • 超类
      • 阶级
每个都有一个名为
do
的方法

调用相应的超类方法的常用方法是什么?
目前我使用的是
.prototype.\uuuuuuuuuuuuuu..调用(this)
,但这看起来很奇怪

控制台使用以下代码打印(如预期的那样):

  • Class.prototype.do
  • 超类.prototype.do
  • SuperSuperClass.prototype.do

调用相应的超类方法的常用方法是什么

使用
.prototype..call(this)
。它不仅更短,而且还具有在不支持非标准
\uuuu proto\uuu
属性的环境中工作的好处

调用相应的超类方法的常用方法是什么


使用
.prototype..call(this)
。它不仅更短,而且还具有在不支持非标准
\uuuu proto\uuu
属性的环境中工作的好处。

Aarg…我以前尝试过类似的方法,但意外使用了
ClassName
。更新的fiddle:使用前面提到的
this.constructor.prototype.do.call(this)
不是解决方案,是吗假设你的
没有覆盖
超类::do
,你会得到类似的无限递归,谢谢你的引用。Aarg…我以前尝试过类似的方法,但无意中使用了
类名
。更新的fiddle:使用前面提到的
this.constructor.prototype.do.call(this)
不是解决方案,是吗假设您的
没有覆盖
超类::do
,您将得到类似于感谢您的引用的无限递归。
SuperSuperClass = function SuperSuperClass() {}
SuperSuperClass.prototype.do = function() {
    console.log('SuperSuperClass.prototype.do');
};

function SuperClass() {
    SuperSuperClass.call(this);
}
SuperClass.prototype = Object.create(SuperSuperClass.prototype);
SuperClass.prototype.constructor = SuperClass;
SuperClass.prototype.do = function() {
    console.log('SuperClass.prototype.do');
    SuperClass.prototype.__proto__.do.call(this);
};

function Class() {
    SuperClass.call(this);
}
Class.prototype = Object.create(SuperClass.prototype);
Class.prototype.constructor = Class;
Class.prototype.do = function() {
    console.log('Class.prototype.do');
    Class.prototype.__proto__.do.call(this);
};

var objClass = new Class();
objClass.do();