4 ms·
class a constructor: -> # conventionally logs 3 console.log @c class b extends a c = 3 new b() # logs undefined
by solox3 13y ago
class a
constructor: ->
# conventionally logs 3
console.log @c
class b extends a
c = 3
new b() # logs undefined
- jashkenas 13y agoNot quite. Key-value properties use the colon syntax. Regular assignment is for local variables. Your "c" is a local variable within the class body of "b", and should absolutely not be visible from the constructor of "a". Here's the corrected version: class a constructor: -> console.log @c class b extends a c: 3 new b() # logs 3
- solox3 13y agoToday the whole office learned. Thanks a bunch, Jeremy!