Using keywords and reserved words as attributes in javascript

The keywords and reserved words that can be used as attributes are

abstract,int,short,boolean,interface,static,byte,long,char,final,native,synchronized,float,package,throws,goto,private,transient,implements,protected,volatile,double,public,supper,implements,package,public,interface,private,static,let,protected,yield

Keywords and reserved words that cannot be used as attributes are

break,do,instanceof,typeof,case,else,new,var,catch,finally,return,void,continue,for,switch,while,debugger,function,this,with,default,if,throw,delete,in,try,enum,export,extends,super,class,const,debugger,import,class,enum,extends,const,export,import

var a={};
a.goto=1;//正常运行
a.this=1;//报错
a['delete']=1;//正确写法

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325629951&siteId=291194637