这是我第一次尝试使用类(或相当于类的 Javascript)。
使用以下代码,我收到错误:在函数参数之前缺少 (。在 Zeile 8
我这里的语法有错误吗?或者是否无法将变量传递给“类方法”?
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");
}
最佳答案
不是
function tagConstructor.prototype.addTag = function
这是
tagConstructor.prototype.addTag = function
关于javascript - 在 Javascript 中将变量传递给类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35342106/