When I globally invoke a function, the this inside it will refer to window.
I have read "Good Part" so I know to workaround it by another variable
"that". But see below example:

I want to append some code to an event handler:

aDiv.onclick = function () {
    var tmpFunc = aDiv.onclick;
    return function () {
        tmpFunc();
        someAnotherFunc();
   }
}();

It almost works well. But if origin onclick contain a this, it will refer to
window because tmpFunc() is a global invocation.
I found a solution, but I think it's not clever:
(If possible I wouldn't like to change origin onclick because it's in
another file)

aDiv.onclick = function () {
    var tmpFunc = aDiv.onclick;
    var tmpObject = aDiv;
    return function () {
        tmpFunc.apply(tmpObject);
        someAnotherFunc();
   }
}();
-- 
Lai, Yu-Hsuan

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to