本文介绍了ES6对象字面值属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在ES6中使用新的简写功能,可以使用 obj.id
并将其解析为 id:obj。 ID
?想知道我是否错过了新的规范...
Using the new shorthand feature in ES6 for object literals, is it possible to use obj.id
and have it parse as id: obj.id
? Wondering if I've missed something in the new spec...
create(obj) {
this.connection.send({
obj.id
});
this.add(obj);
},
推荐答案
不, 。变量只适用于变量,因此您应该使用 {id:obj.id}
。
No, there is not. Shorthands do only work for variables, so you should use {id: obj.id}
.
这篇关于ES6对象字面值属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!