Created
January 10, 2010 16:18
-
-
Save ecavazos/273589 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // using node.js | |
| var sys = require("sys"); | |
| var balls = [1, 2, 3, 4]; | |
| sys.puts("\n// for...in loop: before prototype\n"); | |
| for (var i in balls) { | |
| sys.puts(balls[i]); | |
| } | |
| // => 1, 2, 3, 4 | |
| Array.prototype.sam = function () {}; | |
| Array.prototype.iam = function () {}; | |
| sys.puts("\n// for...in loop: after prototype\n"); | |
| for (var i in balls) { | |
| sys.puts(balls[i]); | |
| } | |
| // => 1, 2, 3, 4, function () {}, function () {} | |
| sys.puts("\n// for loop\n"); | |
| for (var i = 0, ii = balls.length; i < ii; i++) { | |
| sys.puts(balls[i]); | |
| } | |
| // => 1, 2, 3, 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment