6To5 Compiler - use __proto__ for inheritance

前端 未结 3 1403
遥遥无期
遥遥无期 2021-01-22 04:38

As the output of 6to5 I\'ve got the following code:

var _inherits = function (subClass, superClass) {
    if (typeof superClass !== \"function\" && super         


        
3条回答
  •  一整个雨季
    2021-01-22 05:15

    Can anybody describe what for used updating __proto__ property?

    ES6 specs that when classes inherit from each other, the resulting constructor functions should inherit from each other as well. CoreController.isPrototypeOf(Controller) will yield true.

    As i try - it doesn't nothing useful

    It is very useful for inheriting static properties, which are placed on the constructor functions in 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

    Every function is an object in JS. It has a prototype, and it can serve as one.

提交回复
热议问题