Observable.fire - behaviour changed. - Ext JS

In the old code, Observable.fireEvent used fireDirect which looked like this:

YAHOO.util.CustomEvent.prototype.fireDirect = function(){
    var len=this.subscribers.length;
    for (var i=0; i<len; ++i) {
        var s = this.subscribers[i];
        if(s){
            var scope = (s.override) ? s.obj : this.scope;
            if(s.fn.apply(scope, arguments) === false){
                return false;
            }
        }
    }
    return true;
};
See that if the handler does not explicitly return false the event firing code returns true, and if you write your Observable subclass so that handlers may veto the operation by explicitly returning false - your code will still execute if no return statement is executed.

The new code is:

        fire : function(){
            var args = Array.prototype.slice.call(arguments, 0);
            var ls = this.listeners, scope;
            for(var i = 0, len = ls.length; i < len; i++){
                var l = ls[i];
                if(l.fireFn.apply(l.scope, arguments) === false){
                    return false;
                }
            }
        }
It just needs "return true;" adding to the end!
  # 2  
02-23-2007, 09:19 AM

I added it. Personally, I always check === or !== but I am paranoid.

你可能感兴趣的:(ext,prototype,Yahoo)