am2124429
am2124429

Reputation: 475

Passing variables to a class method in Javascript

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");
}

Upvotes: 2

Views: 57

Answers (1)

Andy
Andy

Reputation: 63524

It's not

function tagConstructor.prototype.addTag = function

It's

tagConstructor.prototype.addTag = function

Upvotes: 2

Related Questions