【发布时间】:2015-12-24 13:54:22
【问题描述】:
我在 coffeescript 中创建了 Point 类和 Vector 类。两个类都继承了 MyObject 类,两个类的构造函数都使用 super()。
我想将 Point 转换为 Vector。因此,我尝试编写 Vector.fromPoint() 方法。该方法用作构造函数(new Vector.fromPoint(new Point(x, y)))。
但是,我无法用coffeescript 编写它。可以用coffeescript写吗?我想在 Vector.fromPoint 构造函数中使用 MyObject.constructor 作为 super()。
【问题讨论】:
-
接受Point的构造函数是另一个构造函数。所以我想分开两个构造函数。 fromPoint 方法清楚地表明它是带有 Point 的构造函数。所以我想要 fromPoint 构造函数。我无法想象如何在 fromPoint 中使用 new。 new 调用了哪个构造函数?
标签: coffeescript