You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Yep, you can certainly make dynamic local variables by using with or eval, but as we've discussed before, neither of those are practical options for reasons of both performance and standards-compliance.
Closing as a wontfix. Just to make my personal position clear, I can't imagine a situation in which I'd be in favor of a CoffeeScript feature that depended on with or eval, nor would I be comfortable using a JS library of any kind that depended on them heavily.
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'
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.
The text was updated successfully, but these errors were encountered: