Does anyone know why code within the object literal the “@” (this) references the enclosing object rather than the immediate?
class Example extends Backbone.View
render: ->
test =
num: 10
nextNum: @num + 1 # References "Example" not "test"
You are calling a Hash constructor, and sending params to the constructor. I see this code similar (maybe no the same) to this one:
I think in the above example you can see clearly that
thisis making reference to the outer object and not to thetestinstance itself, among other things because thetestinstance is still not created.In the example above you would resolve the issue like this:
So moving this to your case I think you should solve it in a similar way: