简体   繁体   English

static class 的 Inheritance 属性

[英]Inheritance of static class properties

Static class properties are inherited: Static class 属性被继承:

 const foo = class { static prop = 'this is a static prop' } const bar = class extends foo {} console.log(bar.prop) // 'this is a static prop'

But I thought static properties were akin to the following, which prints undefined as expected:但我认为 static 属性类似于以下内容,它按预期打印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

So is static class property inheritance magical behavior provided over and above ordinary prototypical inheritance? static class 属性 inheritance 提供的神奇行为超出了普通原型 Z5FED3411FAF2032174EF1F042?C

Yes.是的。 extends does this for you: MDN . extends为您执行此操作: MDN You certainly can do an old-school copy/extends for the same behavior.您当然可以为相同的行为做一个老式的复制/扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM