You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					32 lines
				
				925 B
			
		
		
			
		
	
	
					32 lines
				
				925 B
			| 
											3 years ago
										 | import _ from './underscore.js'; | ||
|  | import each from './each.js'; | ||
|  | import { ArrayProto } from './_setup.js'; | ||
|  | import chainResult from './_chainResult.js'; | ||
|  | 
 | ||
|  | // Add all mutator `Array` functions to the wrapper.
 | ||
|  | each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { | ||
|  |   var method = ArrayProto[name]; | ||
|  |   _.prototype[name] = function() { | ||
|  |     var obj = this._wrapped; | ||
|  |     if (obj != null) { | ||
|  |       method.apply(obj, arguments); | ||
|  |       if ((name === 'shift' || name === 'splice') && obj.length === 0) { | ||
|  |         delete obj[0]; | ||
|  |       } | ||
|  |     } | ||
|  |     return chainResult(this, obj); | ||
|  |   }; | ||
|  | }); | ||
|  | 
 | ||
|  | // Add all accessor `Array` functions to the wrapper.
 | ||
|  | each(['concat', 'join', 'slice'], function(name) { | ||
|  |   var method = ArrayProto[name]; | ||
|  |   _.prototype[name] = function() { | ||
|  |     var obj = this._wrapped; | ||
|  |     if (obj != null) obj = method.apply(obj, arguments); | ||
|  |     return chainResult(this, obj); | ||
|  |   }; | ||
|  | }); | ||
|  | 
 | ||
|  | export default _; |