mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Add setToString helper.
This commit is contained in:
30
lodash.js
30
lodash.js
@@ -3781,7 +3781,7 @@
|
|||||||
*/
|
*/
|
||||||
function baseRest(func, start) {
|
function baseRest(func, start) {
|
||||||
start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
|
start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
|
||||||
return function() {
|
return setToString(function() {
|
||||||
var args = arguments,
|
var args = arguments,
|
||||||
index = -1,
|
index = -1,
|
||||||
length = nativeMax(args.length - start, 0),
|
length = nativeMax(args.length - start, 0),
|
||||||
@@ -3797,7 +3797,7 @@
|
|||||||
}
|
}
|
||||||
otherArgs[start] = array;
|
otherArgs[start] = array;
|
||||||
return apply(func, this, otherArgs);
|
return apply(func, this, otherArgs);
|
||||||
};
|
}, func + '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6313,6 +6313,22 @@
|
|||||||
return root.setTimeout(func, wait);
|
return root.setTimeout(func, wait);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the `toString` method of `func` to return `string`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Function} func The function to modify.
|
||||||
|
* @param {Function} string The `toString` result.
|
||||||
|
* @returns {Function} Returns `func`.
|
||||||
|
*/
|
||||||
|
var setToString = !defineProperty ? identity : function(func, string) {
|
||||||
|
return defineProperty(func, 'toString', {
|
||||||
|
'configurable': true,
|
||||||
|
'enumerable': false,
|
||||||
|
'value': constant(string)
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the `toString` method of `wrapper` to mimic the source of `reference`
|
* Sets the `toString` method of `wrapper` to mimic the source of `reference`
|
||||||
* with wrapper details in a comment at the top of the source body.
|
* with wrapper details in a comment at the top of the source body.
|
||||||
@@ -6323,14 +6339,10 @@
|
|||||||
* @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
* @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
||||||
* @returns {Function} Returns `wrapper`.
|
* @returns {Function} Returns `wrapper`.
|
||||||
*/
|
*/
|
||||||
var setWrapToString = !defineProperty ? identity : function(wrapper, reference, bitmask) {
|
function setWrapToString(wrapper, reference, bitmask) {
|
||||||
var source = (reference + '');
|
var source = (reference + '');
|
||||||
return defineProperty(wrapper, 'toString', {
|
return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
|
||||||
'configurable': true,
|
}
|
||||||
'enumerable': false,
|
|
||||||
'value': constant(insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)))
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts `string` to a property path array.
|
* Converts `string` to a property path array.
|
||||||
|
|||||||
Reference in New Issue
Block a user