javascript - Can't read CoffeeScript global variable -
I have two coffeescript files, these are the first lines:
jQuery (document) .ready ($) - & gt; Dispatcher.bind "createuserchannel", (channelid) - & gt; Route = (Exports) This Route. Chainleulus = Dispatcher. Subscribe (Channeled)
and the following are:
jQuery (document) .ready ($) - & gt; Root = (export? This) console.log root.channel_user
I do not know why but in Chrome console when I write Object.keys (window)
channel_user
appears as a global variable but if I try to access it from javascript it is only undefined.
this object (in this case,
do Cument
). You have two options that I see: First of all, you can explicitly use the window
, it is not clear whether This will fit in your case.
root = (export window)
Second, you can use the coffee script fat arrow, the outer scope Keep it by
note that if you depend on elsewhere in that function according to the second this
behavior That may issue.
jQuery (document) .ready ($) = & gt;
I think that this is going on in your second case, but it is impossible to ensure that sender
is not without knowing.
Comments
Post a Comment