underscore-source 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
|
|
1
|
-
// Underscore.js 1.3.
|
1
|
+
// Underscore.js 1.3.1
|
2
2
|
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
|
3
3
|
// Underscore is freely distributable under the MIT license.
|
4
4
|
// Portions of Underscore are inspired or borrowed from Prototype,
|
@@ -62,7 +62,7 @@
|
|
62
62
|
}
|
63
63
|
|
64
64
|
// Current version.
|
65
|
-
_.VERSION = '1.3.
|
65
|
+
_.VERSION = '1.3.1';
|
66
66
|
|
67
67
|
// Collection Functions
|
68
68
|
// --------------------
|
@@ -80,7 +80,7 @@
|
|
80
80
|
}
|
81
81
|
} else {
|
82
82
|
for (var key in obj) {
|
83
|
-
if (
|
83
|
+
if (_.has(obj, key)) {
|
84
84
|
if (iterator.call(context, obj[key], key, obj) === breaker) return;
|
85
85
|
}
|
86
86
|
}
|
@@ -89,7 +89,7 @@
|
|
89
89
|
|
90
90
|
// Return the results of applying the iterator to each element.
|
91
91
|
// Delegates to **ECMAScript 5**'s native `map` if available.
|
92
|
-
_.map = function(obj, iterator, context) {
|
92
|
+
_.map = _.collect = function(obj, iterator, context) {
|
93
93
|
var results = [];
|
94
94
|
if (obj == null) return results;
|
95
95
|
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
|
@@ -506,7 +506,7 @@
|
|
506
506
|
hasher || (hasher = _.identity);
|
507
507
|
return function() {
|
508
508
|
var key = hasher.apply(this, arguments);
|
509
|
-
return
|
509
|
+
return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
|
510
510
|
};
|
511
511
|
};
|
512
512
|
|
@@ -612,7 +612,7 @@
|
|
612
612
|
_.keys = nativeKeys || function(obj) {
|
613
613
|
if (obj !== Object(obj)) throw new TypeError('Invalid object');
|
614
614
|
var keys = [];
|
615
|
-
for (var key in obj) if (
|
615
|
+
for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
|
616
616
|
return keys;
|
617
617
|
};
|
618
618
|
|
@@ -635,7 +635,7 @@
|
|
635
635
|
_.extend = function(obj) {
|
636
636
|
each(slice.call(arguments, 1), function(source) {
|
637
637
|
for (var prop in source) {
|
638
|
-
|
638
|
+
obj[prop] = source[prop];
|
639
639
|
}
|
640
640
|
});
|
641
641
|
return obj;
|
@@ -733,17 +733,17 @@
|
|
733
733
|
if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false;
|
734
734
|
// Deep compare objects.
|
735
735
|
for (var key in a) {
|
736
|
-
if (
|
736
|
+
if (_.has(a, key)) {
|
737
737
|
// Count the expected number of properties.
|
738
738
|
size++;
|
739
739
|
// Deep compare each member.
|
740
|
-
if (!(result =
|
740
|
+
if (!(result = _.has(b, key) && eq(a[key], b[key], stack))) break;
|
741
741
|
}
|
742
742
|
}
|
743
743
|
// Ensure that both objects contain the same number of properties.
|
744
744
|
if (result) {
|
745
745
|
for (key in b) {
|
746
|
-
if (
|
746
|
+
if (_.has(b, key) && !(size--)) break;
|
747
747
|
}
|
748
748
|
result = !size;
|
749
749
|
}
|
@@ -762,7 +762,7 @@
|
|
762
762
|
// An "empty" object has no enumerable own-properties.
|
763
763
|
_.isEmpty = function(obj) {
|
764
764
|
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
|
765
|
-
for (var key in obj) if (
|
765
|
+
for (var key in obj) if (_.has(obj, key)) return false;
|
766
766
|
return true;
|
767
767
|
};
|
768
768
|
|
@@ -788,7 +788,7 @@
|
|
788
788
|
};
|
789
789
|
if (!_.isArguments(arguments)) {
|
790
790
|
_.isArguments = function(obj) {
|
791
|
-
return !!(obj &&
|
791
|
+
return !!(obj && _.has(obj, 'callee'));
|
792
792
|
};
|
793
793
|
}
|
794
794
|
|
@@ -838,6 +838,11 @@
|
|
838
838
|
return obj === void 0;
|
839
839
|
};
|
840
840
|
|
841
|
+
// Has own property?
|
842
|
+
_.has = function(obj, key) {
|
843
|
+
return hasOwnProperty.call(obj, key);
|
844
|
+
};
|
845
|
+
|
841
846
|
// Utility Functions
|
842
847
|
// -----------------
|
843
848
|
|
@@ -892,6 +897,12 @@
|
|
892
897
|
// guaranteed not to match.
|
893
898
|
var noMatch = /.^/;
|
894
899
|
|
900
|
+
// Within an interpolation, evaluation, or escaping, remove HTML escaping
|
901
|
+
// that had been previously added.
|
902
|
+
var unescape = function(code) {
|
903
|
+
return code.replace(/\\\\/g, '\\').replace(/\\'/g, "'");
|
904
|
+
};
|
905
|
+
|
895
906
|
// JavaScript micro-templating, similar to John Resig's implementation.
|
896
907
|
// Underscore templating handles arbitrary delimiters, preserves whitespace,
|
897
908
|
// and correctly escapes quotes within interpolated code.
|
@@ -902,15 +913,13 @@
|
|
902
913
|
str.replace(/\\/g, '\\\\')
|
903
914
|
.replace(/'/g, "\\'")
|
904
915
|
.replace(c.escape || noMatch, function(match, code) {
|
905
|
-
return "',_.escape(" + code
|
916
|
+
return "',_.escape(" + unescape(code) + "),'";
|
906
917
|
})
|
907
918
|
.replace(c.interpolate || noMatch, function(match, code) {
|
908
|
-
return "'," + code
|
919
|
+
return "'," + unescape(code) + ",'";
|
909
920
|
})
|
910
921
|
.replace(c.evaluate || noMatch, function(match, code) {
|
911
|
-
return "');" + code.replace(
|
912
|
-
.replace(/[\r\n\t]/g, ' ')
|
913
|
-
.replace(/\\\\/g, '\\') + ";__p.push('";
|
922
|
+
return "');" + unescape(code).replace(/[\r\n\t]/g, ' ') + ";__p.push('";
|
914
923
|
})
|
915
924
|
.replace(/\r/g, '\\r')
|
916
925
|
.replace(/\n/g, '\\n')
|