major internal reworking -- all variable declarations have been pushed up to the first line of the block scope -- all assignment is now an inherent expression

This commit is contained in:
Jeremy Ashkenas
2009-12-25 22:57:33 -08:00
parent 7c132d65dc
commit adaae0ccae
7 changed files with 77 additions and 60 deletions

View File

@@ -3,24 +3,25 @@
// The cornerstone, an each implementation.
// Handles objects implementing forEach, arrays, and raw objects.
_.each = function(obj, iterator, context) {
var index = 0;
var __a, __b, __c, __d, __e, __f, __g, __h, i, index, item, key;
index = 0;
try {
if (obj.forEach) {
obj.forEach(iterator, context);
} else if (_.isArray(obj) || _.isArguments(obj)) {
var __a = obj;
var __d = [];
for (var __b=0, __c=__a.length; __b<__c; __b++) {
var item = __a[__b];
var i = __b;
__a = obj;
__d = [];
for (__b=0, __c=__a.length; __b<__c; __b++) {
item = __a[__b];
i = __b;
__d[__b] = iterator.call(context, item, i, obj);
}
__d;
} else {
var __e = _.keys(obj);
var __h = [];
for (var __f=0, __g=__e.length; __f<__g; __f++) {
var key = __e[__f];
__e = _.keys(obj);
__h = [];
for (__f=0, __g=__e.length; __f<__g; __f++) {
key = __e[__f];
__h[__f] = iterator.call(context, obj[key], key, obj);
}
__h;

View File

@@ -2,24 +2,25 @@
// The cornerstone, an each implementation.
// Handles objects implementing forEach, arrays, and raw objects.
_.each = function(obj, iterator, context) {
var index = 0;
var __a, __b, __c, __d, __e, __f, __g, __h, i, index, item, key;
index = 0;
try {
if (obj.forEach) {
obj.forEach(iterator, context);
} else if (_.isArray(obj) || _.isArguments(obj)) {
var __a = obj;
var __d = [];
for (var __b=0, __c=__a.length; __b<__c; __b++) {
var item = __a[__b];
var i = __b;
__a = obj;
__d = [];
for (__b=0, __c=__a.length; __b<__c; __b++) {
item = __a[__b];
i = __b;
__d[__b] = iterator.call(context, item, i, obj);
}
__d;
} else {
var __e = _.keys(obj);
var __h = [];
for (var __f=0, __g=__e.length; __f<__g; __f++) {
var key = __e[__f];
__e = _.keys(obj);
__h = [];
for (__f=0, __g=__e.length; __f<__g; __f++) {
key = __e[__f];
__h[__f] = iterator.call(context, obj[key], key, obj);
}
__h;

View File

@@ -1,12 +1,13 @@
(function(){
var object = {
var array, object;
object = {
a: 1,
// Comments between the elements.
b: 2,
// Like this.
c: 3
};
var array = [1,
array = [1,
// Comments between the elements.
2,
// Like this.