Closed
Description
This has been discussed before, but I was playing around with the following which might be a way of getting access to a current context. It's made possible by the fact that CoffeeScript will declare all variables on a scope. So instead, we can define them on an object 'context'
(function() { var context = {x: null, y: null, X: null} var x = 5 var z = 1234 with(context) { x = 1 y = 1 X = {a:3} // mixin for(var i in X) context[i] = X[i] console.log(context) // #object ... console.log(x) // 1 console.log(z) // 1234 console.log(typeof h) // undefined console.log(a) // 3 } })()
Anyway - I'm not entirely sure if it's useful beyond mixing into the current scope, but I thought I'd share it anyway. I imagine that it wouldn't be used unless the script specifically mentioned some kind of 'global' keyword.