mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Fix hasObjectSpliceBug implementations of _#pop, _#shift, and _#splice.
Former-commit-id: 91a3bc259c85bd269c3d895b66204bdc4d158827
This commit is contained in:
10
lodash.js
10
lodash.js
@@ -4399,16 +4399,18 @@
|
|||||||
// avoid array-like object bugs with `Array#shift` and `Array#splice`
|
// avoid array-like object bugs with `Array#shift` and `Array#splice`
|
||||||
// in Firefox < 10 and IE < 9
|
// in Firefox < 10 and IE < 9
|
||||||
if (hasObjectSpliceBug) {
|
if (hasObjectSpliceBug) {
|
||||||
each(['shift', 'splice'], function(methodName) {
|
each(['pop', 'shift', 'splice'], function(methodName) {
|
||||||
var func = lodash.prototype[methodName];
|
var func = arrayRef[methodName],
|
||||||
|
isSplice = methodName == 'splice';
|
||||||
|
|
||||||
lodash.prototype[methodName] = function() {
|
lodash.prototype[methodName] = function() {
|
||||||
var value = this.__wrapped__,
|
var value = this.__wrapped__,
|
||||||
result = func.apply(this, arguments);
|
result = func.apply(value, arguments);
|
||||||
|
|
||||||
if (value.length === 0) {
|
if (value.length === 0) {
|
||||||
delete value[0];
|
delete value[0];
|
||||||
}
|
}
|
||||||
return result;
|
return isSplice ? new lodash(result) : result;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,11 @@
|
|||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
(function() {
|
(function() {
|
||||||
var push = Array.prototype.push,
|
var arrayProto = Array.prototype,
|
||||||
slice = Array.prototype.slice;
|
concat = arrayProto.concat,
|
||||||
|
pop = arrayProto.pop,
|
||||||
|
push = arrayProto.push,
|
||||||
|
slice = arrayProto.slice;
|
||||||
|
|
||||||
if (_.chain) {
|
if (_.chain) {
|
||||||
return;
|
return;
|
||||||
@@ -70,19 +73,19 @@
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
_.prototype.concat = _.wrap(_.prototype.concat, function(func) {
|
_.prototype.concat = function() {
|
||||||
var result = func.apply(this, slice.call(arguments, 1));
|
var result = concat.apply(this.__wrapped__, arguments);
|
||||||
if (this.__chain__) {
|
if (this.__chain__) {
|
||||||
result = new _(result);
|
result = new _(result);
|
||||||
result.__chain__ = true;
|
result.__chain__ = true;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
});
|
};
|
||||||
|
|
||||||
_.prototype.pop = _.wrap(_.prototype.pop, function(func) {
|
_.prototype.pop = function() {
|
||||||
func.apply(this, slice.call(arguments, 1));
|
pop.apply(this.__wrapped__, arguments);
|
||||||
return this;
|
return this;
|
||||||
});
|
};
|
||||||
}());
|
}());
|
||||||
</script>
|
</script>
|
||||||
<script src="../vendor/underscore/test/collections.js"></script>
|
<script src="../vendor/underscore/test/collections.js"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user