提问人:joren 提问时间:1/20/2023 最后编辑:Sebastian Simonjoren 更新时间:1/20/2023 访问量:47
Node.js this.varaiable 分配在 VS Code 中不起作用 [重复]
Node.js this.varaiable assignment not working in VS Code [duplicate]
问:
如果我在其他地方运行它,则在 Node.js 代码下方运行它效果很好,但在 VS Code 中它会抛出错误。
this.k= 8
TypeError: Cannot set properties of undefined (setting 'k')
at subfun (file:///c:/Users/Administrator/Documents/2.js:3:15)
at mainfun (file:///c:/Users/Administrator/Documents/2.js:6:5)
at file:///c:/Users/Administrator/Documents/2.js:8:1
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)
我的代码:
var mainfun = function (){
function subfun(a){
this.k= 8
console.log(this.k)
}
subfun()
}
mainfun()
需要上述解决方案才能在 VS Code 上运行,我正在寻找错误原因。
答: 暂无答案
评论
this.k = 8
this
this