This project is archived and is in readonly mode.

#1027 ✓wontfix

Adding a Break to each

Reported by Arieh | October 4th, 2010 @ 06:50 AM

So, while reading something n the MDC, I figured that mootool's forEach implementation (I assume this is true for the ECMAS' as well) was missing a way to break, and that it was actually quite easy to implement:

      function BreakExcp(){}

  function Break(){
     throw new BreakExcp;

  Object.extend('forEach' , function (object,fn,bind){
            try {
                 for (var key in object){
                    if (object.hasOwnProperty(key)), object[key], key, object);
                if (e instanceof BreakExcep) return;
                throw e;

Doing this will allow me to do:

if (a==3) Break(); console.log(a); }); //1,2

Comments and changes to this ticket

  • Christoph Pojer

    Christoph Pojer October 4th, 2010 @ 10:52 AM

    • State changed from “new” to “wontfix”

    We are not going to add this feature. You can implement this feature easily in your own code.

    The cleanest and fastest way to break from loops is to not use forEach.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket