Dunno if this is the forum for it but I've had a need for a slight
modification to Try.these() from prototype.js. In my situation I
wanted to make sure that as many functions ran as possible instead of
just the first successful.

It's useful in situations where you have a lot of if(object) { /* do
stuff with object */ } statements in a row.

The return value wasn't important to me at the time. so I just chucked
it into an array. Perhaps someone could suggest something better to
return?

So here it is:

Try.allThese = function(){
        var returnValue = [];
        for (var i = 0; i < arguments.length; i++) {
                var lambda = arguments[i];
                try {
                        returnValue.push(lambda());
                } catch (e) {
                        returnValue.push(false);
                }
        }
        return returnValue;
};


--
Andrew
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to