super.call(this)的正确用法是什么



我有一个类函数(不是我最初开发的(。。。

function Project()
{
Project.super.call(this);
// this._some_var = null;
/* other initial vars */
...
return DefensiveObject.create(this); // see comment below
}
function initialize()
{
//*******Initialize Project************
}
...
return Project;

这个函数是称为"函数"的模块的一部分;项目.js"包含在运行nodemain.js.中

return DefensiveObject.create(this); // not return Object.create(this)

DefensiveObject是一个类,用于防止对象获取或设置类中未显式设置的属性。

main.js调用驻留在我的Project类中的Project.initialize((。

我的问题是,为什么需要拨打";Project.super.call(this("?

在Javascript中,ES6类上使用了保留词super来引用子类的父类,使用它来引用函数是没有意义的。

请阅读这篇文章,其中解释了超级的用法

https://jordankasper.com/understanding-super-in-javascript/

这篇中等规模的文章也可以帮助你https://medium.com/beginners-guide-to-mobile-web-development/super-and-extends-in-javascript-es6-understanding-the-tough-parts-6120372d3420

Project.super.call(this(行是允许在"一次性";类(不包括在原始问题中(,允许从内存中清理代码。

最新更新