剩余模式...

对象的属性太多,没得那么多变量(一来是没必要,二来是懒),写了几个变量后就懒得写了。

咋办?

把对象中剩余的元素统统收集起来,放到   ...   

 1 let options = {
 2   title: "Menu",
 3   height: 200,
 4   width: 100
 5 };
 6 
 7 // title = 名为 title 的属性
 8 // rest = 存有剩余属性的对象
 9 let {title, ...rest} = options;
10 
11 // 现在 title="Menu", rest={height: 200, width: 100}
12 alert(rest.height);  // 200
13 alert(rest.width);   // 100

 

posted @ 2020-12-16 22:08  呈心者  阅读(82)  评论(0编辑  收藏  举报