waypoint commit on the big merge

This commit is contained in:
Jeremy Ashkenas
2010-02-24 12:03:08 -05:00
parent 2ec05e758b
commit 39024c35a6

View File

@@ -22,31 +22,31 @@
var escapeRegExp = function(s) { return s.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); }; var escapeRegExp = function(s) { return s.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); };
// Save bytes in the minified (but not gzipped) version: // Save bytes in the minified (but not gzipped) version:
var Array_Prototype = Array.prototype; var ArrayProto = Array.prototype, ObjProto = Object.prototype;
// Create quick reference variables for speed access to core prototypes. // Create quick reference variables for speed access to core prototypes.
var slice = Array_Prototype.slice, var slice = ArrayProto.slice,
unshift = Array_Prototype.unshift, unshift = ArrayProto.unshift,
toString = Object.prototype.toString, toString = ObjProto.toString,
hasOwnProperty = Object.prototype.hasOwnProperty, hasOwnProperty = ObjProto.hasOwnProperty,
propertyIsEnumerable = Object.prototype.propertyIsEnumerable; propertyIsEnumerable = ObjProto.propertyIsEnumerable;
// All native implementations we hope to use are declared here. // All native implementations we hope to use are declared here.
var var
native_forEach = Array_Prototype.forEach, native_forEach = ArrayProto.forEach,
native_map = Array_Prototype.map, native_map = ArrayProto.map,
native_reduce = Array_Prototype.reduce, native_reduce = ArrayProto.reduce,
native_reduceRight = Array_Prototype.reduceRight, native_reduceRight = ArrayProto.reduceRight,
native_filter = Array_Prototype.filter, native_filter = ArrayProto.filter,
native_every = Array_Prototype.every, native_every = ArrayProto.every,
native_some = Array_Prototype.some, native_some = ArrayProto.some,
native_indexOf = Array_Prototype.indexOf, native_indexOf = ArrayProto.indexOf,
native_lastIndexOf = Array_Prototype.lastIndexOf, native_lastIndexOf = ArrayProto.lastIndexOf,
native_isArray = Array['isArray'], // use [] notation since not in closure's externs native_isArray = Array['isArray'], // use [] notation since not in closure's externs
native_keys = Object['keys']; native_keys = Object['keys'];
// Create a safe reference to the Underscore object for reference below. // Create a safe reference to the Underscore object for reference below.
var _ = function(obj) { return _.buildWrapper(obj) }; var _ = function(obj) { return _.buildWrapper(obj); };
// Export the Underscore object for CommonJS. // Export the Underscore object for CommonJS.
if (typeof exports !== 'undefined') exports._ = _; if (typeof exports !== 'undefined') exports._ = _;
@@ -74,8 +74,6 @@
for (var key in obj) for (var key in obj)
if (hasOwnProperty.call(obj, key)) if (hasOwnProperty.call(obj, key))
iterator.call(context, obj[key], key, obj); iterator.call(context, obj[key], key, obj);
// var keys = _.keys(obj), l = keys.length;
// for (var i=0; i<l; i++) iterator.call(context, obj[keys[i]], keys[i], obj);
} }
} catch(e) { } catch(e) {
if (e != breaker) throw e; if (e != breaker) throw e;
@@ -589,7 +587,7 @@
// looks good in wrapper form: // looks good in wrapper form:
// _(3).times(alert) // _(3).times(alert)
_.times = function (n, fn, context) { _.times = function (n, fn, context) {
for (var i=0; i < n; i++) fn.call(context, i) for (var i = 0; i < n; i++) fn.call(context, i);
}; };
// Break out of the middle of an iteration. // Break out of the middle of an iteration.
@@ -645,9 +643,9 @@
_.methods = _.functions; _.methods = _.functions;
// ------------------------ Setup the OOP Wrapper: -------------------------- // ------------------------ Setup the OOP Wrapper: --------------------------
_.buildWrapper = function () { throw "Call _.initWrapper() to enable OO wrapping" } _.buildWrapper = function() { throw "Call _.initWrapper() to enable OO wrapping"; };
_.initWrapper = function () { _.initWrapper = function() {
if (_._wrapper) return; // Already initialized if (_._wrapper) return; // Already initialized
// If Underscore is called as a function, it returns a wrapped object that // If Underscore is called as a function, it returns a wrapped object that
@@ -660,7 +658,7 @@
_._wrapper = wrapper; _._wrapper = wrapper;
// Overwrite method called from _() // Overwrite method called from _()
_.buildWrapper = function (obj) { return new wrapper(obj) }; _.buildWrapper = function (obj) { return new wrapper(obj); };
// Helper function to continue chaining intermediate results. // Helper function to continue chaining intermediate results.
var result = function(obj, chain) { var result = function(obj, chain) {
@@ -679,7 +677,7 @@
// Add all mutator Array functions to the wrapper. // Add all mutator Array functions to the wrapper.
each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
var method = Array_Prototype[name]; var method = ArrayProto[name];
wrapper.prototype[name] = function() { wrapper.prototype[name] = function() {
method.apply(this._wrapped, arguments); method.apply(this._wrapped, arguments);
return result(this._wrapped, this._chain); return result(this._wrapped, this._chain);
@@ -688,7 +686,7 @@
// Add all accessor Array functions to the wrapper. // Add all accessor Array functions to the wrapper.
each(['concat', 'join', 'slice'], function(name) { each(['concat', 'join', 'slice'], function(name) {
var method = Array_Prototype[name]; var method = ArrayProto[name];
wrapper.prototype[name] = function() { wrapper.prototype[name] = function() {
return result(method.apply(this._wrapped, arguments), this._chain); return result(method.apply(this._wrapped, arguments), this._chain);
}; };
@@ -704,7 +702,7 @@
wrapper.prototype.value = function() { wrapper.prototype.value = function() {
return this._wrapped; return this._wrapped;
}; };
} };
// For backwards compatability, init the OO wrapper // For backwards compatability, init the OO wrapper
// the advanced minifying rake task will strip this out // the advanced minifying rake task will strip this out