-1

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
    }
}
2
  • That looks like minified code. You better should look into the original source to understand what happens. Commented 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. Commented Oct 9, 2024 at 8:36

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

But why would anyone not want to just set focus. Why do 2 lines of code as above rather than simpler AVSetFocus(params);
I don't know. I'm just explaining the code that you've shown, I can't explain what the person who wrote it intended, especially when I don't know what the 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...
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();

2 Comments

Thanks for info but in this case the function is a library function and pretty sure that calling the function like AVSetFocus() does in fact set focus to the element.
No it does not call the FocusMgr.SetFocusToField. The f variable just refers to that function, but it is not called in any way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.