In CoffeeScript, if I define an instance property in a class constructor, that property can refer to other instance properties in its definition, for example:
class Foo
constructor: (data) ->
@One = 1
@Two = @One + 1
But what about instance properties declared at the class level? The following does not work:
class Foo
One: 1
Two: @One + 1
In that context, the @ symbol refers to the ‘class’ itself, not the instance. Likewise simply removing the @ does not work.
Is there a way that one instance property declared at the class level can refer to another instance property in its definition?
When you say this:
You’re setting
oneonFoo‘s prototype so you just have to look at@‘s prototype to get back to whereoneis:Demo
Note that this even works with subclasses so you do this:
and you’ll get the expected three.