1

I get

Uncaught SyntaxError: Unexpected identifier

in the marked line below. I have no idea what to do. Tried all sorts of things but it seems like a fundamental mistake I have made.

class Order {

constructor(pVornameS, pNachnameS, pKlasseS, pVornameE, pNachnameE, pKlasseE) {
    this.vornameS = pVornameS;
    this.nachnameS = pNachnameS;
    this.klasseS = pKlasseS;
    this.vornameE = pVornameE;
    this.nachnameE = pNachnameE;
    this.klasseE = pKlasseE;
}

function getVornameS() { //The error occurs in this line
    return vornameS;
}

function getNachnameS() {
    return nachnameS;
}

function getKlasseS() {
    return klasseS;
}

function getVornameE() {
    return vornameE;
}

function getNachnameE() {
    return nachnameE;
}

function getKlasseE() {
    return klasseE;
}
}
2
  • 4
    Just remove function. Commented Feb 28, 2018 at 16:37
  • 2
    Also you will need to use this.… to access your properties in the getter methods Commented Feb 28, 2018 at 16:38

1 Answer 1

5

You don't need the function keyword in there. Starting with ECMAScript 2015, a shorter syntax for method definitions on objects initializers is introduced. It is a shorthand for a function assigned to the method's name.

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

1 Comment

That was very helpful!

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.