javascript - 如何修复“未捕获的语法错误:无效的速记属性初始值设定项”
问题描述
即使 VSCODE 显示代码中没有错误,为什么我会遇到这个问题
var person={
firstname:"koushik",
sayHi : function()
{
console.log("hello there "+this.firstname)
},
check : function()
{
console.log (this===person)
}
}
console.log(person)
我期望 person 对象的输出,但收到错误 Uncaught SyntaxError: Invalid shorthand property initializer
编辑:键firstname
在分配值时有语法错误,=
而不是:
解决方案
var person={
firstname:"koushik",
sayHi : function()
{
console.log("hello there "+this.firstname)
},
check : function()
{
console.log (this===person)
}
}
console.log(person)
您可以使用此代码。有什么问题在这里看到https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Missing_colon_after_property_id
另一个提示:尝试在 Firefox 的 Web 控制台中运行您的代码
推荐阅读
- angular - 使用 Angular 4 / ionic 在模板中显示 const
- c++ - 如何在C++中创建一个n行5列的数组,但是n值在变化
- oracle - SQL避免在select语句中两次调用相同的函数
- python - Python - 删除 datafeame 单元格中的重复项
- spring - SpringBoot 不扫描命名包
- google-cloud-dataflow - 不可调试的数据流异常
- git - 将 Gitlab 分支迁移到另一个项目的最快方法
- graphql - Apollo Angular:突变后,调用watchQuery方法未获取最新数据
- angular - 如何排除 angular.json 中的脚本文件?
- python-2.7 - 如何使用 Matplolib 创建交互式 Colorbar?