2

This is the first time I'm trying to work with classes (or the Javascript equivalent to classes).

With the following code I get the error: Missing ( before function parameters. in Zeile 8

Do I have some error in the syntax here? Or is it not possible to pass variables to a "class method"?

function tagConstructor() {
    this.tagTypeList = [
        "brand",
        "category",
    ];
    this.tags = {};
}
function tagConstructor.prototype.addTag = function(tagType, tag) { // This is line 8 where the error occurs
    // Only add tag if tag type exists in tagTypeList
    if (this.tagTypeList.indexOf(tagType) > -1) {
        this.tags[tagType] = tag;
    }
}
function main() {
    var test = new tagConstructor();
    test.addTag("brand", "Adidas");
    test.addTag("gender", "Damen");
}

1 Answer 1

2

It's not

function tagConstructor.prototype.addTag = function

It's

tagConstructor.prototype.addTag = function
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.