-1

I am loading a script with the jQuery getScript function after the document is ready. The script has these 2 lines:

const myNameSpace={};

function myNameSpace.test() {
}

I am getting this error:

error message

I have used NameSpaces elsewhere in the project in the same way and did not get this error.

1 Answer 1

7

You can't use a property name in a function declaration. The parameter has to be a single identifier.

You can write

myNameSpace.test = function() { };

or put the function definition directly in the object literal

const myNameSpace = {
    test() { }
}
Sign up to request clarification or add additional context in comments.

Comments

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.