admin管理员组文章数量:1406937
Is it possible to use reserved keywords in an object destructuring assignment?
Specifically I am trying to handle JSON with property named default.
//Doesn't pile
class FooBar {
constructor({foo, default}) {
this.foo = foo;
this.default = default;
}
}
/* json from server {foo: "bar", default: true} */
new FooBar(json);
Is it possible to use reserved keywords in an object destructuring assignment?
Specifically I am trying to handle JSON with property named default.
//Doesn't pile
class FooBar {
constructor({foo, default}) {
this.foo = foo;
this.default = default;
}
}
/* json from server {foo: "bar", default: true} */
new FooBar(json);
Share
Improve this question
edited Oct 1, 2023 at 12:59
jonrsharpe
122k30 gold badges268 silver badges476 bronze badges
asked Oct 3, 2018 at 21:03
Steven WexlerSteven Wexler
17.4k8 gold badges57 silver badges83 bronze badges
2
- 1 Seems like a better design to just not used reserved words since they're, y'know, reserved. – Paul Commented Oct 3, 2018 at 21:07
- @Paul when working with vue + storybook, using the default keyword for slots is normal, and removing from the args is also quite useful. – Gustavo Fenilli Commented Feb 22, 2022 at 18:30
1 Answer
Reset to default 10It'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;
}
}
本文标签: javascriptEscape reserved keywords in object destructuring assignmentStack Overflow
版权声明:本文标题:javascript - Escape reserved keywords in object destructuring assignment - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744374410a2603187.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论