晚上好,
有人可以帮助我并告诉我为什么我的 javascript 代码收到错误吗? SyntaxError: 意外的数字 (at script.js:15:24) 仅供参考:我的 javascript 上的第 15 行是函数 Person(Harry, 22)。
function Person(Harry, 22) {
this.name = Harry;
this.age = 22;
}
console.log(Person);
我期待看到他的名字和年龄。
JS 函数应该只在括号内传递有效的参数名称。 (22 不是有效的参数名称)。
无论如何,如果您要对姓名和年龄进行硬编码,则不一定将其作为参数传递。
function Person() {
this.name = 'Harry';
this.age = 22;
}
console.log(Person);