mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Remove argument juggling from _.before.
This commit is contained in:
@@ -6648,13 +6648,7 @@
|
|||||||
function before(n, func) {
|
function before(n, func) {
|
||||||
var result;
|
var result;
|
||||||
if (typeof func != 'function') {
|
if (typeof func != 'function') {
|
||||||
if (typeof n == 'function') {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
var temp = n;
|
|
||||||
n = func;
|
|
||||||
func = temp;
|
|
||||||
} else {
|
|
||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return function() {
|
return function() {
|
||||||
if (--n > 0) {
|
if (--n > 0) {
|
||||||
|
|||||||
12
test/test.js
12
test/test.js
@@ -1190,18 +1190,6 @@
|
|||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should allow `func` as the first argument', 1, function() {
|
|
||||||
var count = 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
var before = _.before(function() { count++; }, 2);
|
|
||||||
before();
|
|
||||||
before();
|
|
||||||
} catch(e) {}
|
|
||||||
|
|
||||||
strictEqual(count, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should not set a `this` binding', 2, function() {
|
test('should not set a `this` binding', 2, function() {
|
||||||
var before = _.before(2, function() { return ++this.count; }),
|
var before = _.before(2, function() { return ++this.count; }),
|
||||||
object = { 'count': 0, 'before': before };
|
object = { 'count': 0, 'before': before };
|
||||||
|
|||||||
Reference in New Issue
Block a user