在 Javascript 中声明空对象属性的简写有吗?
我需要在脚本中声明很多对象属性,我想知道是否有任何方法可以缩短它:
Core.registry.taskItemSelected;
Core.registry.taskItemSelected.id;
Core.registry.taskItemSelected.name;
Core.registry.taskItemSelected.parent;
Core.registry.taskItemSelected.summary;
Core.registry.taskItemSelected.description;
I need to declare a lot of object properties in my script and I wonder if the're any way to shorten this:
Core.registry.taskItemSelected;
Core.registry.taskItemSelected.id;
Core.registry.taskItemSelected.name;
Core.registry.taskItemSelected.parent;
Core.registry.taskItemSelected.summary;
Core.registry.taskItemSelected.description;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那行不通?
Wouldn't that work?
像这样的东西应该有效:
编辑:按照OP评论,这里是具有相同最终结果的更好版本:
还有实时测试用例: http://jsfiddle.net/5fRDc/
Something like this should work:
Edit: following the OP comments, here is better version with same final result:
And live test case as well: http://jsfiddle.net/5fRDc/