-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathCallbackExamplejQuery.js
More file actions
42 lines (38 loc) · 1.38 KB
/
CallbackExamplejQuery.js
File metadata and controls
42 lines (38 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// args is for internal usage only
each: function( obj, callback, args ) { //note que args não faz parte da API pública
var i = 0,
length = obj.length,
isArray = isArraylike( obj );
if ( args ) { //aqui trata quando há algo interno acontecendo
if ( isArray ) {
for ( ; i < length; i++ ) {
if ( callback.apply( obj[ i ], args ) === false ) {
break;
}
}
} else {
for ( i in obj ) {
if ( callback.apply( obj[ i ], args ) === false ) {
break;
}
}
}
// A special, fast, case for the most common use of each
} else { //tratamento do caso público que é que nos interessa
if ( isArray ) { //tratamento especial se for um array
for ( ; i < length; i++ ) { //varrrrá todo array passado
if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
break; //encerra quando a chama acima falhar
}
}
} else { //outros objetos
for ( i in obj ) { //vai analisar cada elemento do objeto passado
if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
break;
}
}
}
}
return obj;
},
//https://pt.stackoverflow.com/q/47828/101