静态类属性是继承的:
const foo = class { static prop = 'this is a static prop' }
const bar = class extends foo {}
console.log(bar.prop) // 'this is a static prop'
但是我认为静态属性类似于以下内容,它们可以undefined
按预期方式打印:
const foo = function() {}
foo.prop = 'this is a static prop'
const bar = function() {}
bar.prototype = Object.create(foo.prototype)
bar.prototype.constructor = bar
console.log(bar.prop) // undefined
那么,静态类属性继承的神奇行为是否超出了普通原型继承?
是。extends
为您做到这一点:MDN。您当然可以针对相同的行为进行老式复制/扩展。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句