gpt4 book ai didi

prototype - 6To5 编译器 - 使用 __proto__ 进行继承

转载 作者:行者123 更新时间:2023-12-01 22:33:01 25 4
gpt4 key购买 nike

作为 6to5 的输出,我得到了以下代码:

var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
// question is about next row
if (superClass) subClass.__proto__ = superClass;
};
_inherits(Controller, CoreController);

任何人都可以描述用于更新 __proto__ 属性的内容吗?正如我尝试的那样 - 它没有任何用处

附言作为documentation says该原型(prototype)应该是对象,但在代码中用于设置功能

最佳答案

Can anybody describe what for used updating __proto__ property?

ES6 规范当类相互继承时,生成的构造函数也应该相互继承。 CoreController.isPrototypeOf(Controller) 将产生 true

As i try - it doesn't nothing useful

对于继承静态属性非常有用,在JS中是放在构造函数上的。

CoreController.hi = console.log.bind(console, "hello world");
CoreController.hi(); // hello world
Controller.hi(); // error
_inherits(Controller, CoreController);
Controller.hi(); // hello world

documentation says that proto should be object, but in code is used for setting function

在 JS 中,每个函数都是一个对象。它有一个原型(prototype),它可以作为一个。

关于prototype - 6To5 编译器 - 使用 __proto__ 进行继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28674356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com