in this code:
class MyClass
myfun: (arg) ->
for x in arg
do ->
...
the scope outside of the loop is MyClass, while inside of the loop (it’s an anonymous function) the scope changes to the DOMWindow.
Why does this happen? How can I prevent it? My main problem is that I can’t access other functions inside the MyClass class if the scope changes.
thanks
Use the fat arrow syntax to bind the a function to the current context:
This happens because the
dokeyword just calls the function without any context, so it defaults to thewindowobject.Is equivalent to