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
if (typeof a === "undefined" || a === null) {
a = {};
}
if (a['b'] == null) {
a['b'] = {};
}
if (a['b']['c'] == null) {
a['b']['c'] = {};
}
if (a['b']['c']['d'] == null) {
a['b']['c']['d'] = {};
}
a.b.c.d = 10;
alert("a.b.c.d = " + a.b.c.d);
Context
As Coffeescript doesn't require variables do be declared before assigning values to them, I'd expect that a missing key in a object hadn't to be declared either before an assignment to that key. This way it would be much easier to represent a sparse matrices as objects.
I've got the "possible solution" above using this code in CoffeeScript:
Are you suggesting that a.b = 5 should automatically prepend a ?= {}? This seems likely dangerous and bad, as it's using JavaScript notation with a very non-JavaScript meaning.
I could imagine a different operator like a!.b = 5 (or some other notation) that automatically does a ?= {} before a.b = 5, though.
Feature request
Input Code
Expected Behavior
a.b.c.d = 10
Current Behavior
error;
Possible Solution
var a;
if (typeof a === "undefined" || a === null) {
a = {};
}
if (a['b'] == null) {
a['b'] = {};
}
if (a['b']['c'] == null) {
a['b']['c'] = {};
}
if (a['b']['c']['d'] == null) {
a['b']['c']['d'] = {};
}
a.b.c.d = 10;
alert("a.b.c.d = " + a.b.c.d);
Context
As Coffeescript doesn't require variables do be declared before assigning values to them, I'd expect that a missing key in a object hadn't to be declared either before an assignment to that key. This way it would be much easier to represent a sparse matrices as objects.
I've got the "possible solution" above using this code in CoffeeScript:
a = {} unless a?
a['b'] = {} unless a['b']?
a['b']['c'] = {} unless a['b']['c']?
a['b']['c']['d'] = {} unless a['b']['c']['d']?
a.b.c.d = 10
alert("a.b.c.d = " + a.b.c.d)
Environment
The text was updated successfully, but these errors were encountered: