0

我有这个代码

var testObject = new TestObject();
testObject.init();

function TestObject() {
    this.init = function() {
        var uiCtrlDescriptors = {
            "htmlElem": "elem",
            "controller" : new Controller(this.htmlElem)
        }
    }    
}

而且我不明白为什么在这一行内this等于:testObject

"controller" : new Controller(this.htmlElem)

而不是等于uiCtrlDescriptors对象?

4

1 回答 1

2

这就是this工作原理。每当你这样做:

obj.some_function();

然后some_function运行this设置为obj.

于 2013-10-28T07:41:38.990 回答