|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
984 bytes
|
| Line | |
|---|
| 1 | var underscore = require('./underscore.js');
|
|---|
| 2 | var each = require('./each.js');
|
|---|
| 3 | var _setup = require('./_setup.js');
|
|---|
| 4 | var _chainResult = require('./_chainResult.js');
|
|---|
| 5 |
|
|---|
| 6 | // Add all mutator `Array` functions to the wrapper.
|
|---|
| 7 | each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
|
|---|
| 8 | var method = _setup.ArrayProto[name];
|
|---|
| 9 | underscore.prototype[name] = function() {
|
|---|
| 10 | var obj = this._wrapped;
|
|---|
| 11 | if (obj != null) {
|
|---|
| 12 | method.apply(obj, arguments);
|
|---|
| 13 | if ((name === 'shift' || name === 'splice') && obj.length === 0) {
|
|---|
| 14 | delete obj[0];
|
|---|
| 15 | }
|
|---|
| 16 | }
|
|---|
| 17 | return _chainResult(this, obj);
|
|---|
| 18 | };
|
|---|
| 19 | });
|
|---|
| 20 |
|
|---|
| 21 | // Add all accessor `Array` functions to the wrapper.
|
|---|
| 22 | each(['concat', 'join', 'slice'], function(name) {
|
|---|
| 23 | var method = _setup.ArrayProto[name];
|
|---|
| 24 | underscore.prototype[name] = function() {
|
|---|
| 25 | var obj = this._wrapped;
|
|---|
| 26 | if (obj != null) obj = method.apply(obj, arguments);
|
|---|
| 27 | return _chainResult(this, obj);
|
|---|
| 28 | };
|
|---|
| 29 | });
|
|---|
| 30 |
|
|---|
| 31 | module.exports = underscore;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.