listen.js
/* I will set a attribute on an obj such that any methods listened via the listen() method will fire. */
I will set a attribute on an obj such that any methods listened via the listen() method will fire.
I will set a attribute on an obj such that any methods listened via the listen () method will fire .
function send(obj, attr, val){ 
    if(val === undefined) val = obj[attr]; 
    var args = Array();
    for(var i = 0; i < arguments.length ; i ++)
        args.push(arguments[i]);
    args = args.length > 3 ? args.slice(2) : false;
    if(!obj.__listeners__ || !obj.__listeners__[attr])
        return;
    var regAttrs = obj.__listeners__[attr];
    var to_run = [];   
    for(var i = 0; i < regAttrs.length; i ++)
        to_run.push([regAttrs[i][0], regAttrs[i][1]]);
    if(args === false){
        for(var i = 0; i < to_run.length; i ++)
            if(to_run[i][0])
                to_run[i][0].call(to_run[i][1] ? to_run[i][1] : obj, val, obj, attr);
    }
    else{
        for(var i = 0; i < to_run.length; i ++)
            if(to_run[i][0])
                to_run[i][0].apply(to_run[i][1] ? to_run[i][1] : obj, args);
    }   
    return obj;
}
function send ( obj , attr , val ) { if ( val === undefined ) val = obj [ attr ] ; var args = Array ( ) ; for ( var i = 0 ; i < arguments . length ; i ++ ) args . push ( arguments [ i ] ) ; args = args . length > 3 ? args . slice ( 2 ) : false ; if ( ! obj . __listeners__ || ! obj . __listeners__ [ attr ] ) return ; var regAttrs = obj . __listeners__ [ attr ] ; var to_run = [ ] ; for ( var i = 0 ; i < regAttrs . length ; i ++ ) to_run . push ( [ regAttrs [ i ] [ 0 ] , regAttrs [ i ] [ 1 ] ] ) ; if ( args === false ) { for ( var i = 0 ; i < to_run . length ; i ++ ) if ( to_run [ i ] [ 0 ] ) to_run [ i ] [ 0 ] . call ( to_run [ i ] [ 1 ] ? to_run [ i ] [ 1 ] : obj , val , obj , attr ) ; } else { for ( var i = 0 ; i < to_run . length ; i ++ ) if ( to_run [ i ] [ 0 ] ) to_run [ i ] [ 0 ] . apply ( to_run [ i ] [ 1 ] ? to_run [ i ] [ 1 ] : obj , args ) ; } return obj ; }
I will set a attribute on an obj such that any methods listened via the listen() method will fire.
I will set a attribute on an obj such that any methods listened via the listen () method will fire .
/* if no val given use current val of object */ /* we look at the raw arguments coming in 
       to decide if we've been given one or more then
       one value, and so to either .call or .apply this
       value(s) below */ /* determine if we have args to use or not. is either
       the list of arguments to send or false */ /* if there are no listeners, just return. */ /* get a reference to the listeners list */ /* it is CRUCIALLY important to the listening algorithm that one cache the entries to 
       call BEFORE calling them in sequence, as they may alter this list during their execution 
       and while we want that, it means we must rely on a second list to iterate over everything
       correctly! */ /* if we are not applying the value, call the method with a single argument */ /* if we ARE being told to apply the value (via the applyValFlag), we will use
       the list-val as the arguments to use in an .apply call. */