在对象销毁分配中转义保留的关键字 [英] Escape reserved keywords in object destructing assignment
本文介绍了在对象销毁分配中转义保留的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在销毁对象的分配中使用保留关键字.
Is it possible to use reserved keywords in an object destructing assignment.
具体地说,我正在尝试使用名为default的属性处理JSON.
Specifically I am trying to handle JSON with property property named default.
//Doesn't compile
class FooBar {
constructor({foo, default}) {
this.foo = foo;
this.default = default;
}
}
/* json from server {foo: "bar", default: true} */
new FooBar(json);
推荐答案
可以将它们用作属性名称,但不能用作变量名称.选择其他目标:
It's possible to use them as a property name, but not as a variable name. Choose a different target:
class FooBar {
constructor({foo, default: def}) {
this.foo = foo;
this.default = def;
}
}
这篇关于在对象销毁分配中转义保留的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文