Use native Object.create when available, optimize the creation of lodash instances, and ensure methods like forEach return the existing wrapper object when chaining, instead of creating a new one.

Former-commit-id: fa9ec371ba23ce8c35c15a66dd9b1f09f183b3a9
This commit is contained in:
John-David Dalton
2013-03-03 01:19:04 -08:00
parent aa49ce5c56
commit 8825a094ae
3 changed files with 104 additions and 39 deletions

View File

@@ -179,8 +179,8 @@
ok(_() instanceof _);
});
test('should return passed LoDash instances', function() {
var wrapped = _([]);
test('should return passed `lodash` instances', function() {
var wrapped = _(false);
equal(_(wrapped), wrapped);
});
}());
@@ -810,11 +810,16 @@
QUnit.module('lodash.forEach');
(function() {
test('returns the collection', function() {
test('should return the collection', function() {
var collection = [1, 2, 3];
equal(_.forEach(collection, Boolean), collection);
});
test('should return the existing wrapper when chaining', function() {
var wrapper = _([1, 2, 3]);
equal(wrapper.forEach(Boolean), wrapper);
});
_.each({
'literal': 'abc',
'object': Object('abc')
@@ -901,6 +906,12 @@
_.each(['assign', 'defaults', 'merge'], function(methodName) {
var func = _[methodName];
test('should return the existing wrapper when chaining', function() {
var wrapper = _({ 'a': 1 });
equal(wrapper[methodName]({ 'b': 2 }), wrapper);
});
test('lodash.' + methodName + ' should assign problem JScript properties (test in IE < 9)', function() {
var object = {
'constructor': '0',