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
|
// V1
// Array
$.each([1, 2, 3], function() {
alert(typeof(this)); // Retourne "object"
});
$.each([1, 2, 3], function(value, index) {
alert(typeof(value)); // Retourne "number"
});
// JSON
$.each({un: 1, deux: 2, trois: 3}, function() {
alert(typeof(this)); // Retourne "object"
});
$.each({un: 1, deux: 2, trois: 3}, function(key, value) {
alert(typeof(value)); // Retourne "number"
});
// V2
// Array
$.each([function() { alert("F1"); }, function() { alert("F2"); }, function() { alert("F3"); }], function() {
alert(typeof(this)); // Retourne "function"
});
$.each([function() { alert("F1"); }, function() { alert("F2"); }, function() { alert("F3"); }], function(value, index) {
alert(typeof(value)); // Retourne "function"
});
// JSON
$.each({one: function() { alert("F1"); }, two: function() { alert("F2"); }, three: function() { alert("F3"); }}, function() {
alert(typeof(this)); // Retourne "function"
});
$.each({one: function() { alert("F1"); }, two: function() { alert("F2"); }, three: function() { alert("F3"); }}, function(key, fn) {
alert(typeof(fn)); // Retourne "function"
}); |
Partager