1. Default Value of function param:

The function displayTopicsPreview() raises an error on the very first line when called with no arguments. Let's fix that!

function displayTopicsPreview( topics ){
var message = "There are currently " + topics.length;
_displayPreviewMessage(topics, message);
} ----------------- function displayTopicsPreview( topics = [] ){
let message = "There are currently " + topics.length;
_displayPreviewMessage(topics, message);
}

2. Complete the setPageThread() function signature with the missing named parameters. You can check out the body of the function to help discover what options are expected.

function setPageThread(name,  ){
let nameElement = _buildNameElement(name);
let settings = _parseSettings(popular, expires, activeClass); _updateThreadElement(nameElement, settings);
} ------------------- function setPageThread(name, {popular, expires, activeClass}){
let nameElement = _buildNameElement(name);
let settings = _parseSettings(popular, expires, activeClass); _updateThreadElement(nameElement, settings);
}

3. Let's refactor the loadProfiles() function to use named parameters with default values.

function loadProfiles(userNames = [], options = {}) {
let profilesClass = options.profilesClass || ".user-profile";
let reverseSort = options.reverseSort || false; if (reverseSort) {
userNames = _reverse(userNames);
} _loadProfilesToSideBar(userNames, profilesClass);
} ------------------------------ function loadProfiles(userNames = [], {profilesClass, reverseSort} = {}) {
profilesClass = profilesClass || ".user-profile";
reverseSort = reverseSort || false; if (reverseSort) {
userNames = _reverse(userNames);
} _loadProfilesToSideBar(userNames, profilesClass);
}
function setPageThread(name, {popular, expires, activeClass} = {}){
// ...
} setPageThread("ES2015", {
popular: true
}); //won't cause error

Important to take away from here is

  • Instead of giving options = {} in the function param, we give {profileClass, reserseSort} = {}
  • First it is more clear to see what "options" it is
  • Second we assign default param here.

[ES6] Function Params的更多相关文章

  1. echarts-中的事件-- demo1.on('事件类型', function (params) {}

    ECharts 支持常规的鼠标事件类型,包括 'click'.'dblclick'.'mousedown'.'mousemove'. 'mouseup'.'mouseover'.'mouseout'. ...

  2. [ES6] 06. Arrow Function =>

    ES6 arrow function is somehow like CoffeeScirpt. CoffeeScript: //function call coffee = -> coffee ...

  3. ES6 new syntax of Default Function Parameters

    Default Function Parameters.md Default Function Parameters function getSum(a,b){ a = (a !== undefine ...

  4. ES6的一些常用特性

    由于公司的前端业务全部基于ES6开发,于是给自己开个小灶补补ES6的一些常用特性.原来打算花两天学习ES6的,结果花了3天才勉强过了一遍阮老师的ES6标准入门(水好深,ES6没学好ES7又来了...) ...

  5. ES6,ES2105核心功能一览,js新特性详解

    ES6,ES2105核心功能一览,js新特性详解 过去几年 JavaScript 发生了很大的变化.ES6(ECMAScript 6.ES2105)是 JavaScript 语言的新标准,2015 年 ...

  6. ES6的编码风格

    编程风格 [转自http://es6.ruanyifeng.com/#docs/style] 块级作用域 字符串 解构赋值 对象 数组 函数 Map结构 Class 模块 ESLint的使用 本章探讨 ...

  7. ES6简单入门

    let let命令用来声明块级作用域. 以前的JavaScript只有全局作用域和函数作用域, 没有块级作用域. // 示例1: if (1) { var a = "hello"; ...

  8. ES6 | ES6新语法 在编码实践中的应用

    本章探讨如何将 ES6 的新语法,运用到编码实践之中,与传统的 JavaScript 语法结合在一起,写出合理的.易于阅读和维护的代码. 多家公司和组织已经公开了它们的风格规范,本文的内容主要参考了  ...

  9. ES6学习笔记(二十一)编程风格

    本章探讨如何将 ES6 的新语法,运用到编码实践之中,与传统的 JavaScript 语法结合在一起,写出合理的.易于阅读和维护的代码. 1.块级作用域 (1)let 取代 var ES6 提出了两个 ...

随机推荐

  1. WinAPI——模拟正弦波

    /*************************** * * 程序名称 : 模拟正弦波 * 作 者 : doodle777 * 版 本 : 1.1 * 日 期 : 2012-10-19 * 说 明 ...

  2. mssql 2008 失败 需要重新启动计算机 的解决办法

    大致出错信息如下:RebootRequiredCheck 检查是否需要挂起计算机重新启动.挂起重新启动会导致安装程序失败. 失败 需要重新启动计算机.必须重新启动计算机才能安装 SQL Server. ...

  3. BitmapImage使用FileStream读取文件

    var bitmapImage = new BitmapImage(); using (FileStream fs = new FileStream(file.FullName, FileMode.O ...

  4. 若后台的Activity被系统回收...

    你后台的Activity被系统回收怎么办?如果后台的Activity由于某种原因被系统回收了,如何在被系统回收之前保存当前状态? 除了在栈顶的Activity,其他的Activity都有可能在内存不足 ...

  5. Oracle Union All 排序

    在oracle中使用union all或者 union 对两个结果集进行并集操作时,如果需要对查询结果集进行排序时,不能直接在后面加order by + 表字段 来排序 例如: 在oracle的soc ...

  6. ActiveRecord 模式杂谈

    ActiveRecord也属于ORM(对象关系映射)层,由Rails最早提出,遵循标准的ORM模型:表映射到记录,记录映射到对象,字段映射到对象属性.配合遵循的命名和配置惯例,能够很大程度的快速实现模 ...

  7. 【结构型】Flyweight模式

    享元模式的主要目的.意图是为对象的大量使用提供一种共享机制.该模式的思想重在复用.共享复用.像文字.列表中的格子等这类多数都是需要考虑复用技术,否则必将大量耗费内存空间而使资源以及性能等大量耗费.该模 ...

  8. bayes

    from numpy import * import time starttime = time.time() def loadDataSet(): postingList = [['my', 'do ...

  9. jdk-map-hashMap

    关于java中的HashMap,我们在项目中经常使用到,但是我们的场景是否使用对了呢? 下面分为四个部分来阐述我的HashMap的理解 1.为什么要使用hashMap? 在项目中,需求的实现需要使用到 ...

  10. 信息安全实验二:return-to-libc

    title: return-to-libc date: 2016-01-11 17:40:30 categories: information-security tags: return-to-lib ...