Mercurial > nebulaweb3
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/default/node_modules/shoestring/src/core/each.js Sat May 31 09:21:51 2025 +0800 @@ -0,0 +1,35 @@ +//>>excludeStart("exclude", pragmas.exclude); +define([ "shoestring" ], function(){ +//>>excludeEnd("exclude"); + + /** + * Iterates over `shoestring` collections. + * + * @param {function} callback The callback to be invoked on each element and index + * @return shoestring + * @this shoestring + */ + shoestring.fn.each = function( callback ){ + return shoestring.each( this, callback ); + }; + + shoestring.each = function( collection, callback ) { + var val; +//>>includeStart("development", pragmas.development); + if( !( "length" in collection ) ) { + shoestring.error( 'each-length' ); + } +//>>includeEnd("development"); + for( var i = 0, il = collection.length; i < il; i++ ){ + val = callback.call( collection[i], i, collection[i] ); + if( val === false ){ + break; + } + } + + return collection; + }; + +//>>excludeStart("exclude", pragmas.exclude); +}); +//>>excludeEnd("exclude");