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
}
}
-
That looks like minified code. You better should look into the original source to understand what happens.Bergi– Bergi2013年04月14日 12:07:45 +00:00Commented Apr 14, 2013 at 12:07
-
This question is similar to: What do curly braces in expression position mean in JavaScript?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.dumbass– dumbass2024年10月09日 08:36:28 +00:00Commented Oct 9, 2024 at 8:36
2 Answers 2
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.
2 Comments
FocusMgr object is. Given you can set focus using the built-in DOM element .focus() method I don't know why you need a special custom function for it at all, but you wanted the syntax explained so at least now you know that much...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();