Javascript python';node.js中的s\uu getitem\uu
Python的getitem使类作为字典工作 但是node.js的类中有没有做类似事情的函数 我的文件内容如下所示Javascript python';node.js中的s\uu getitem\uu,javascript,node.js,Javascript,Node.js,Python的getitem使类作为字典工作 但是node.js的类中有没有做类似事情的函数 我的文件内容如下所示 const{readFileSync,writeFileSync}=require('fs')) 类JSONManager{ 构造函数(文件名,编码='utf8'){ this.filename=文件名 this.content=JSON.parse( readFileSync(文件名,编码) ) } 提交(){ writeFileSync( 此文件名为.filename, JSO
const{readFileSync,writeFileSync}=require('fs'))
类JSONManager{
构造函数(文件名,编码='utf8'){
this.filename=文件名
this.content=JSON.parse(
readFileSync(文件名,编码)
)
}
提交(){
writeFileSync(
此文件名为.filename,
JSON.stringify(this.content)
)
}
}
但是我不想像classname.content[value]
那样使用。我想使用likeclassname[value]
(很抱歉没有告诉您确切的目的)以上代码是有效的javascript。我的错误。编辑你能详细说明一下你在这里想要达到的目标吗?所有javascript对象都可以作为字典使用breace或dot语法..Edited(抱歉多次编辑)您的意思是