开发者

Javascript : How to get reference to the parent object inside a child object

I have the followi开发者_如何学Gong code, where i'm unable to get a reference to the parent object inside OnKeyUp function. I understand that in the OnKeyUp method, "this" refers to the textbox. But how do i access the parent object so that var textboxID gets me the correct value ?

       function $MyObject() {

        this.Control = {

            inputBox: "#inputBox1",

            name: "Control1",

            BindEvent: function () {
                $(this.inputBox).keyup(this.OnKeyUp);
            },


            OnKeyUp: function () {
                var textBoxID = this.inputBox;
                alert(textBoxID);
            }


        }
    }


    $(document).ready(function () {

        var object1 = new $MyObject();
        object1.Control.BindEvent();

    });


function $MyObject() {
    var self = this.Control = {

        inputBox: "#inputBox1",

        name: "Control1",

        BindEvent: function () {
            $(self.inputBox).keyup(self.OnKeyUp);
        },


        OnKeyUp: function () {
            var textBoxID = self.inputBox;
            alert(textBoxID);
        }


    };
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜