Created
January 13, 2012 22:50
-
-
Save dherman/1609202 to your computer and use it in GitHub Desktop.
using loop controls from within block lambdas
This file contains 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
Mailbox.prototype.extractContents = function(contacts) { | |
let messages = this.messages; | |
loop: | |
for (let i = 0, n = messages.length; i < n; i++) { | |
messages[i].headers.forEach { |header| | |
if (header.isSpam()) | |
continue loop; // the label is not strictly necessary here | |
let addresses = header.extractAddresses(); | |
addresses.forEach { |addr| | |
contacts.add(addr.name, addr.email); | |
}; | |
}; | |
} | |
}; |
I just want to point out that this is what I mean about goto and FUD. Not that labels are true gotos, not that any form of goto is harmful. But that people will want to argue about it. We will be spending a lot of our time correcting people's misconceptions. And in the end, the consensus will be, "look just don't use labels, you don't need them if you know how to write good javascript". They are not a useful feature of javascript and they should be avoided. We've managed to do it for this long. Let's not falter now.
Yes I do realize that I'm the one that first mentioned goto. Call it a preliminary social experiment that served to fully support my hypothesis.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I commented more verbosely on Isaac's gist, but in short: what about disallowing mixing of block lambda return and normal return in a single function?