Reputation: 9708
Can someone please explain this javascript syntax.
What does n: { } mean?
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?
So AVSetFocus is returning an object and a function and an array. Does this function actually call SetFocusToField?
What is this style called?
Bit confused.
function AVSetFocus(d, b) {
return {
n: {
t: FocusMgr,
f: FocusMgr.SetFocusToField,
a: [d, b]
}
}
}
Just also found this:
var FocusMgr;
function FocusMgr_Init() {
FocusMgr = new function () {
this.mCurFocusID = 0;
this.mCurFocusWindowID = 0;
this.mCurFocusElement = null;
this.mOpenedWindow = false;
this.mFocusStk = [];
//etc
}
}
Upvotes: -1
Views: 105
Reputation: 150010
The AvSetFocus()
function returns this object:
{
n: {
t: FocusMgr,
f: FocusMgr.SetFocusToField,
a: [d, b]
}
}
The object has one property, "n"
, which itself refers to another object:
{
t: FocusMgr,
f: FocusMgr.SetFocusToField,
a: [d, b]
}
...which in turn has three properties. "t"
refers to (presumably) yet another object, "f"
refers to a method of same object "t"
refers to, which seems a little redundant since you could access that via ""t
, and "a"
ends up referring to an array of the two values passed into AvSetFocus()
as parameters.
"Does this function actually call SetFocusToField?"
No it doesn't. You might use it something like:
var avsf = AvSetFocus(x, y);
avsf.n.f(); // calls FocusMgr.SetFocusToField()
Or you could do this:
AvSetFocus(x, y).n.f();
As for what the parameters you pass to AvSetFocus()
should be, I have no idea - from the code shown there's no way to tell.
Upvotes: 2
Reputation: 785
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();
Upvotes: 0