Reputation: 5800
So in javascript I would dynamically call a function from a string like this:
window["function_name"](args);
However if I try this in coffeescript it does not work, is this something to do with the way coffee script does not have a function in the global namespace?
All of the functions are wrapped in a function like this:
(function() {
#code here
}).call(this);
So how do I call a function from a string in coffeescript?
Upvotes: 0
Views: 236
Reputation: 430
I tried here ("Try Coffescript" section) this (sorry about identation):
( ->
foo = () ->
alert "it works" ;
).call(this); #IFFE on Coffescript
window["foo"]() ;
And it seems to work
Upvotes: 2
Reputation: 254
window["function_name"](args);
This code in CoffeeScript compiles to:
window["function_name"](args);
in javscript.
So the problem is not CoffeeScript, but your code.
Upvotes: 0