【发布时间】:2013-06-20 08:31:50
【问题描述】:
我正在使用 Webstorm 6.0.2 并在尝试使用 mixin 语法时遇到错误:
class A{}
class B with A{} //error can't use with syntax without an extends?
为什么我不能在没有extends 的情况下使用with?当然每个类都隐含extends Object。
【问题讨论】:
我正在使用 Webstorm 6.0.2 并在尝试使用 mixin 语法时遇到错误:
class A{}
class B with A{} //error can't use with syntax without an extends?
为什么我不能在没有extends 的情况下使用with?当然每个类都隐含extends Object。
【问题讨论】:
这里是a really clear explanation from Ladislav Thon:
[...] 有一个简单的建议,实际上在语义上是正确的:在声明 class C extends SC with M1, M2, M3 implements I1, I2 { ... } 中,想象一下extends 子句内容的括号。它们看起来像这样:class C extends (SC with M1, M2, M3) implements I1, I2 { ... }。这意味着 C 类没有扩展 SC,它扩展了 SC_with_M1_with_M2_with_M3。
或者,换一种说法:类声明有一个extends子句和一个implements子句,但它没有有一个with 子句。相反,with 子句属于 extends 子句。
还有another point from Florian Loitsch:
当你用 mixin 扩展“Object”时,第一个 mixin 总是可以代替“Object”。
所以你的class B with A 应该是class B extends Object with A,也相当于class B extends A。
【讨论】:
A 的限制。