function _inherits(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
}
});
if (superClass)
Object.setPrototypeOf
? Object.setPrototypeOf(subClass, superClass)
: (subClass.__proto__ = superClass);
}
上面是babel转码后的效果,其中这段代码
if (superClass)
Object.setPrototypeOf
? Object.setPrototypeOf(subClass, superClass)
: (subClass.__proto__ = superClass);
问题:1.这段代码不加我觉得也算实现继承了吧?看高程里面貌似也没有给子类的构造函数设置__proto__的代码啊?设置跟不设置有多大区别?
__proto__印象中不是只有对象才有么?虽然js里面一切皆对象,但是常见的故事new 出来的实例会讲到它的__proto__,函数的__proto__怎么理解?
青春有我
相关分类