0

有人可以解释一下这个javascript语法吗?

n: { } 是什么意思?

是不是意味着 AVSetFocus 返回了一个 nobject(已经被赋予了临时名称 n,它由 'fields' t、f 和 a 组成。t 是一个对象(看起来像),f 是对象 t 的一个函数,并且a 是一个数组?

所以 AVSetFocus 返回一个对象、一个函数和一个数组。这个函数真的调用 SetFocusToField 吗?

这种风格叫什么?

有点糊涂。

function AVSetFocus(d, b) {
    return {
        n: {
            t: FocusMgr,
            f: FocusMgr.SetFocusToField,
            a: [d, b]
        }
    }
}

刚刚还发现了这个:

var FocusMgr;

function FocusMgr_Init() {
    FocusMgr = new function () {
        this.mCurFocusID = 0;
        this.mCurFocusWindowID = 0;
        this.mCurFocusElement = null;
        this.mOpenedWindow = false;
        this.mFocusStk = [];
        //etc
    }
}
4

2 回答 2

2

AvSetFocus()函数返回此对象:

{
    n: {
        t: FocusMgr,
        f: FocusMgr.SetFocusToField,
        a: [d, b]
    }
}

该对象有一个属性 ,"n"它本身引用另一个对象:

    {
        t: FocusMgr,
        f: FocusMgr.SetFocusToField,
        a: [d, b]
    }

...它又具有三个属性。"t"引用(可能)另一个对象,"f"引用同一个对象的方法"t"引用,这似乎有点多余,因为您可以访问该 via ""t,并最终引用作为参数"a"传入的两个值的数组。AvSetFocus()

“这个函数真的调用 SetFocusToField 吗?”

不,它没有。你可能会像这样使用它:

var avsf = AvSetFocus(x, y);
avsf.n.f();  // calls FocusMgr.SetFocusToField()

或者你可以这样做:

AvSetFocus(x, y).n.f();

至于您传递给的参数AvSetFocus()应该是什么,我不知道 - 从显示的代码中无法判断。

于 2013-04-14T11:51:09.233 回答
0

Does it mean that AVSetFocus returns a nobject (which has been given the temporary name, n, which consists of 'fields' t, f and a. t is an object (looks like), f is a function of the object t, and a is an array?

{} is the object literal notation. It creates a new object. So yes you are correct.

The f variable is just a reference to the method, but it is not executed.

You can call the function by doing n.f();

于 2013-04-14T11:48:16.897 回答