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;
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744374411a4571113.html
评论列表(0条)