comparison default/node_modules/shoestring/src/core/each.js @ 0:1d038bc9b3d2 default tip

Up:default
author Liny <dev@neowd.com>
date Sat, 31 May 2025 09:21:51 +0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1d038bc9b3d2
1 //>>excludeStart("exclude", pragmas.exclude);
2 define([ "shoestring" ], function(){
3 //>>excludeEnd("exclude");
4
5 /**
6 * Iterates over `shoestring` collections.
7 *
8 * @param {function} callback The callback to be invoked on each element and index
9 * @return shoestring
10 * @this shoestring
11 */
12 shoestring.fn.each = function( callback ){
13 return shoestring.each( this, callback );
14 };
15
16 shoestring.each = function( collection, callback ) {
17 var val;
18 //>>includeStart("development", pragmas.development);
19 if( !( "length" in collection ) ) {
20 shoestring.error( 'each-length' );
21 }
22 //>>includeEnd("development");
23 for( var i = 0, il = collection.length; i < il; i++ ){
24 val = callback.call( collection[i], i, collection[i] );
25 if( val === false ){
26 break;
27 }
28 }
29
30 return collection;
31 };
32
33 //>>excludeStart("exclude", pragmas.exclude);
34 });
35 //>>excludeEnd("exclude");