mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Expose _.noop. [closes #380]
This commit is contained in:
46
lodash.js
46
lodash.js
@@ -390,15 +390,6 @@
|
|||||||
return typeof value.toString != 'function' && typeof (value + '') == 'string';
|
return typeof value.toString != 'function' && typeof (value + '') == 'string';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A no-operation function.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function noop() {
|
|
||||||
// no operation performed
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Releases the given array back to the array pool.
|
* Releases the given array back to the array pool.
|
||||||
*
|
*
|
||||||
@@ -1133,14 +1124,18 @@
|
|||||||
}
|
}
|
||||||
// fallback for browsers without `Object.create`
|
// fallback for browsers without `Object.create`
|
||||||
if (!nativeCreate) {
|
if (!nativeCreate) {
|
||||||
baseCreate = function(prototype) {
|
baseCreate = (function() {
|
||||||
if (isObject(prototype)) {
|
function Object() {}
|
||||||
noop.prototype = prototype;
|
|
||||||
var result = new noop;
|
return function(prototype) {
|
||||||
noop.prototype = null;
|
if (isObject(prototype)) {
|
||||||
}
|
Object.prototype = prototype;
|
||||||
return result || {};
|
var result = new Object;
|
||||||
};
|
Object.prototype = null;
|
||||||
|
}
|
||||||
|
return result || context.Object();
|
||||||
|
};
|
||||||
|
}());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6134,6 +6129,22 @@
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-operation function.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Utilities
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* var object = { 'name': 'fred' };
|
||||||
|
* _.noop(object) === undefined;
|
||||||
|
* // => true
|
||||||
|
*/
|
||||||
|
function noop() {
|
||||||
|
// no operation performed
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the given value into an integer of the specified radix.
|
* Converts the given value into an integer of the specified radix.
|
||||||
* If `radix` is `undefined` or `0` a `radix` of `10` is used unless the
|
* If `radix` is `undefined` or `0` a `radix` of `10` is used unless the
|
||||||
@@ -6754,6 +6765,7 @@
|
|||||||
lodash.lastIndexOf = lastIndexOf;
|
lodash.lastIndexOf = lastIndexOf;
|
||||||
lodash.mixin = mixin;
|
lodash.mixin = mixin;
|
||||||
lodash.noConflict = noConflict;
|
lodash.noConflict = noConflict;
|
||||||
|
lodash.noop = noop;
|
||||||
lodash.parseInt = parseInt;
|
lodash.parseInt = parseInt;
|
||||||
lodash.random = random;
|
lodash.random = random;
|
||||||
lodash.reduce = reduce;
|
lodash.reduce = reduce;
|
||||||
|
|||||||
32
test/test.js
32
test/test.js
@@ -3791,15 +3791,14 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return `false` for non objects', 3, function() {
|
test('should return `false` for non objects', 1, function() {
|
||||||
var expected = _.map(falsey, function() { return false; });
|
var values = falsey.concat('a', true),
|
||||||
|
expected = _.map(values, function() { return false; });
|
||||||
|
|
||||||
var actual = _.map(falsey, function(value, index) {
|
var actual = _.map(values, function(value, index) {
|
||||||
return index ? _.isObject(value) : _.isObject();
|
return index ? _.isObject(value) : _.isObject();
|
||||||
});
|
});
|
||||||
|
|
||||||
strictEqual(_.isObject(true), false);
|
|
||||||
strictEqual(_.isObject('a'), false);
|
|
||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -4761,6 +4760,23 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('lodash.noop');
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
test('should always return `undefined`', 1, function() {
|
||||||
|
var values = falsey.concat([], true, new Date, _, {}, /x/, 'a'),
|
||||||
|
expected = _.map(values, function() { return undefined; });
|
||||||
|
|
||||||
|
var actual = _.map(values, function(value, index) {
|
||||||
|
return index ? _.noop(value) : _.noop();
|
||||||
|
});
|
||||||
|
|
||||||
|
deepEqual(actual, expected);
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('lodash.omit');
|
QUnit.module('lodash.omit');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
@@ -5609,7 +5625,9 @@
|
|||||||
expected = _.map(falsey, function() { return undefined; });
|
expected = _.map(falsey, function() { return undefined; });
|
||||||
|
|
||||||
_.forEach(falsey, function(value, index) {
|
_.forEach(falsey, function(value, index) {
|
||||||
actual.push(index ? _.result(value) : _.result());
|
try {
|
||||||
|
actual.push(index ? _.result(value) : _.result());
|
||||||
|
} catch(e) { }
|
||||||
});
|
});
|
||||||
|
|
||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
@@ -7657,7 +7675,7 @@
|
|||||||
|
|
||||||
var acceptFalsey = _.difference(allMethods, rejectFalsey);
|
var acceptFalsey = _.difference(allMethods, rejectFalsey);
|
||||||
|
|
||||||
test('should accept falsey arguments', 148, function() {
|
test('should accept falsey arguments', 149, function() {
|
||||||
var isExported = '_' in root,
|
var isExported = '_' in root,
|
||||||
oldDash = root._;
|
oldDash = root._;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user