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
bareoption in the second argument ofcompile:But you could also use
CoffeeScript.evaldirectly. It will do just what you’re looking for 🙂