mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Cleanup compareAscending and createBound.
Former-commit-id: e783a68666aaea16d917fa1db74d2092e5dcaa9a
This commit is contained in:
39
lodash.js
39
lodash.js
@@ -240,19 +240,16 @@
|
||||
* @returns {Number} Returns the sort order indicator of `1` or `-1`.
|
||||
*/
|
||||
function compareAscending(a, b) {
|
||||
var ai = a.index,
|
||||
bi = b.index;
|
||||
|
||||
a = a.criteria;
|
||||
b = b.criteria;
|
||||
var ac = a.criteria;
|
||||
bc = b.criteria;
|
||||
|
||||
// ensure a stable sort in V8 and other engines
|
||||
// http://code.google.com/p/v8/issues/detail?id=90
|
||||
if (a !== b) {
|
||||
if (a > b || typeof a == 'undefined') {
|
||||
if (ac !== bc) {
|
||||
if (ac > bc || typeof ac == 'undefined') {
|
||||
return 1;
|
||||
}
|
||||
if (a < b || typeof b == 'undefined') {
|
||||
if (ac < bc || typeof bc == 'undefined') {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -260,7 +257,7 @@
|
||||
// `Array#sort` implementation that causes it, under certain circumstances,
|
||||
// to return the same value for `a` and `b`.
|
||||
// See https://github.com/jashkenas/underscore/pull/1247
|
||||
return ai < bi ? -1 : (ai > bi ? 1 : 0);
|
||||
return a.index - b.index;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1431,8 +1428,9 @@
|
||||
* 1 - `_.bind`
|
||||
* 2 - `_.bindKey`
|
||||
* 4 - `_.curry`
|
||||
* 8 - `_.partial`
|
||||
* 16 - `_.partialRight`
|
||||
* 8 - `_.curry` (bound)
|
||||
* 16 - `_.partial`
|
||||
* 32 - `_.partialRight`
|
||||
* @param {Array} [partialArgs] An array of arguments to prepend to those
|
||||
* provided to the new function.
|
||||
* @param {Array} [partialRightArgs] An array of arguments to append to those
|
||||
@@ -1445,8 +1443,9 @@
|
||||
var isBind = bitmask & 1,
|
||||
isBindKey = bitmask & 2,
|
||||
isCurry = bitmask & 4,
|
||||
isPartial = bitmask & 8,
|
||||
isPartialRight = bitmask & 16;
|
||||
isCurryBound = bitmask & 8,
|
||||
isPartial = bitmask & 16,
|
||||
isPartialRight = bitmask & 32;
|
||||
|
||||
if (!isBindKey && !isFunction(func)) {
|
||||
throw new TypeError;
|
||||
@@ -1456,6 +1455,9 @@
|
||||
if (isBind && !(bindData[1] & 1)) {
|
||||
bindData[4] = thisArg;
|
||||
}
|
||||
if (!isBind && bindData[1] & 1) {
|
||||
bitmask |= 8;
|
||||
}
|
||||
if (isCurry && !(bindData[1] & 4)) {
|
||||
bindData[5] = arity;
|
||||
}
|
||||
@@ -1490,7 +1492,8 @@
|
||||
push.apply(args, partialRightArgs);
|
||||
}
|
||||
if (isCurry && args.length < arity) {
|
||||
return createBound(func, 12, args, null, null, arity);
|
||||
bitmask |= 16 & ~32
|
||||
return createBound(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity);
|
||||
}
|
||||
if (isBindKey) {
|
||||
func = thisBinding[key];
|
||||
@@ -5070,7 +5073,7 @@
|
||||
* // => 'hi moe'
|
||||
*/
|
||||
function bind(func, thisArg) {
|
||||
return createBound(func, 9, nativeSlice.call(arguments, 2), null, thisArg);
|
||||
return createBound(func, 17, nativeSlice.call(arguments, 2), null, thisArg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -5144,7 +5147,7 @@
|
||||
* // => 'hi, moe!'
|
||||
*/
|
||||
function bindKey(object, key) {
|
||||
return createBound(object, 11, nativeSlice.call(arguments, 2), null, key);
|
||||
return createBound(object, 19, nativeSlice.call(arguments, 2), null, key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -5571,7 +5574,7 @@
|
||||
* // => 'hi moe'
|
||||
*/
|
||||
function partial(func) {
|
||||
return createBound(func, 8, nativeSlice.call(arguments, 1));
|
||||
return createBound(func, 16, nativeSlice.call(arguments, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -5602,7 +5605,7 @@
|
||||
* // => { '_': _, 'jq': $ }
|
||||
*/
|
||||
function partialRight(func) {
|
||||
return createBound(func, 16, null, nativeSlice.call(arguments, 1));
|
||||
return createBound(func, 32, null, nativeSlice.call(arguments, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user