相关疑难解决方法(0)

ES6解构对象赋值函数参数默认值

嗨,我在这里通过函数参数Object Destructuring Demo经历了对象解构的使用示例

function drawES6Chart({size = 'big', cords = { x: 0, y: 0 }, radius = 25} = **{}**) {
  console.log(size, cords, radius);
 // do some chart drawing
}

 // In Firefox, default values for destructuring assignments are not yet  
 implemented (as described below). 
 // The workaround is to write the parameters in the following way:
   // ({size: size = 'big', cords: cords = { x: 0, y: 0 }, radius: radius =  
      25} = **{}**)

 drawES6Chart({ …
Run Code Online (Sandbox Code Playgroud)

javascript object destructuring ecmascript-6

3
推荐指数
3
解决办法
1713
查看次数

标签 统计

destructuring ×1

ecmascript-6 ×1

javascript ×1

object ×1