首页 > 其他 > 详细

TypeScript之解构赋值

时间:2018-05-20 10:23:58      阅读:468      评论:0      收藏:0      [点我收藏+]

一 数组的解构赋值

 

const heroes: string[] = [];
const turtles: string[] = [‘Leo‘, ‘Raph‘, ‘Mikey‘, ‘Don‘];
console.log(...turtles);
heroes.push(...turtles);
console.log(heroes);

 

技术分享图片

 

 二 对象的结构赋值

 

const name = ‘iPhone‘;
const color = ‘gold‘;
console.log(JSON.stringify({ name, color }));

 

技术分享图片

 

const phone = {
  name: ‘iPhone‘,
  color: ‘gold‘
};

const car = {
  name: ‘Ferrari‘,
  color: ‘red‘
};

console.log(JSON.stringify({ phone, car }));

 

技术分享图片

 

TypeScript之解构赋值

原文:https://www.cnblogs.com/sea-breeze/p/9062468.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!