I am using coffee-script.js to let me compile little snippets of coffeescript into javascript inside the browser. This lets me do:
eval(Coffeescript.compile("console.log 'yo'"))
But this returns a wrapped function, like this:
(function() {
console.log('yo')
}).call(this);
I would like to get an unwrapped snippet of code, so that I can call functions that would be in scope if it wasn't for the function wrapper. Any suggestions apart from a regex to strip it out by hand?
You can pass the bare
option in the second argument of compile
:
// In JS
CoffeeScript.compile("console.log 'yo'", {bare: true})
# In CS :)
CoffeeScript.compile "console.log 'yo'", bare: on
But you could also use CoffeeScript.eval
directly. It will do just what you're looking for :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With