0

I have pretty simple JS

function () {          //**Expected identifier** over first bracket
    window.Root = {
        Models : {},
        Views : {},
        Comments : {}

    }
}
.call(this) //**Syntax error** over dot

But getting an errors

function () - Expected identifier

. call(this) - Syntax error

Could some one explain why that errors talking place and how to fix that?

2 Answers 2

2

You've forgotten the parentheses:

(function () {
    window.Root = {
        Models: {},
        Views: {},
        Comments: {}
    }
}).call(this);

Because expressions cannot start with function or {, it is treated as a declaration and therefore fails. Function declarations must have an identifier, and since .call is completely separate from the function declaration, it is therefore a syntax error (as .call(this) in itself is not a valid statement).

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

Comments

0

You have missed the paranthesis in your function.

(function () {          //**Expected identifier** over first bracket
window.Root = {
    Models : {},
    Views : {},
    Comments : {}

}
});
.call(this) //**Syntax error** over dot

1 Comment

Don't need the semi-colon if you're chaining the call method

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.