javascript binding

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2010-05-09T03:02:27Z Indexed on 2010/05/09 3:08 UTC
Read the original article Hit count: 310

Filed under:
|
MyObj = 
{
    ajax: null,
    init: function()
    {
        this.ajax = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
        this.ajax.onload = function()
        {
            return function() {this.onload.apply(this, [null]);}
        };
    },
    onload: function ()
    {
        Reader.log("I really hope I can use `this.ajax` here");
    }
}

isn't it correct way to bind onload to MyObj? For some reason onload never called. However if I avoid binding and just put this.ajax.onload = this.onload then onload invoked. How to get binding work?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about binding