Search code examples
javascriptmootools

mootools or javascript : what does $tmp stand for or what does it pertain too


I'm currently working on the Tips.js from mootools library and my code breaks on the line that has those el.$tmp, and console says it's undefined

Can anybody help me?


Solution

  • in 1.11 (haven't checked in 1.2+) $tmp is a reference to the element itself, created and used internally by the garbage collector:

    var Garbage = {
    
        elements: [],
    
        collect: function(el){
            if (!el.$tmp){
                Garbage.elements.push(el);
                el.$tmp = {'opacity': 1};
            }
            return el;
        },
    
        trash: function(elements){
            for (var i = 0, j = elements.length, el; i < j; i++){
                if (!(el = elements[i]) || !el.$tmp) continue;
                if (el.$events) el.fireEvent('trash').removeEvents();
                for (var p in el.$tmp) el.$tmp[p] = null;
                for (var d in Element.prototype) el[d] = null;
                Garbage.elements[Garbage.elements.indexOf(el)] = null;
                el.htmlElement = el.$tmp = el = null;
            }
            Garbage.elements.remove(null);
        },
    
        empty: function(){
            Garbage.collect(window);
            Garbage.collect(document);
            Garbage.trash(Garbage.elements);
        }
    
    };
    

    the lines el.$tmp = {'opacity': 1}; (in collect method above) and el.htmlElement = el.$tmp = el = null; (in trash method above) are the only places in the source where this property is assigned that i could find, although it's called by various other methods, such as Element.setOpacity and Element.getStyle (specifically, only to return opacity value), as well as methods in the Tips class

    1.2 might not have this issue, but in any case, hope that helps and sorry i couldn't help more