Closed iccir closed 9 years ago
The scope of the object
variable would be limited to the @each
block.
Also, this would only be for arrays. It would transpile into something like:
for (var $oj_each_UUID_i = 0, $oj_each_UUID_length = arr.length; $oj_each_UUID_i < $oj_each_UUID_length; $oj_each_UUID_i++) {
var $oj_each_UUID_object = arr[i];
// All occurrences of object identifier replaced by $oj_each_UUID_object
}
Actually, we should use the same semantics as for-in loops.
var object;
@each (object in arr) { }
@each (var object in arr) { }
@each (let object in arr) { }
In general, I'm not a fan of "let's make oj a complex language!"
That said, I think there is benefit to adding a very basic iterator for array-like objects.
Right now, the following is the fastest way to loop in most js engines:
Using
_.each
orArray#forEach
looks nicer, but it performs slower:There is also no nice way to
break
, andreturn
is used forcontinue
. This has led to programming errors when refactoring (See #35)Hence, I'm proposing: