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. java反射新的应用

    利用java反射动态修改运行中对象的私有final变量,不管有没有get方法获取这个私有final变量. spring aop 本质是cglib,动态代理 可以做很多事情 query.addCrite ...

  2. Lesson 5: Typography in Product Design

    Lesson 5: Typography in Product Design Article 1: Interactive Guide to Blog Typography 布局(Layout) 用空 ...

  3. linux定时执行任务 转

    转自:http://www.cnblogs.com/thinksasa/archive/2013/06/06/3121030.html linux定时执行任务   (1)Linux下如何定时执行php ...

  4. 【转】解析JDK 7的动态类型语言支持

    http://www.infoq.com/cn/articles/jdk-dynamically-typed-language Java虚拟机的字节码指令集的数量自从Sun公司的第一款Java虚拟机问 ...

  5. Linux "top" 命令解析

    TOP命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况.   TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户 ...

  6. DBA优化SQL采用的WITH AS 用法简介

    一.WITH AS简介 WITH AS的用法从oracle 9i新增的,官方文档也称之为:subquery factoring;在进行复杂的查询.统计等操作时使用with as 子句可以大大提高性能! ...

  7. Oracle数据库简介

    Oracle数据库简介 一.介绍 Oracle数据库系统是美国Oracle(甲骨文)公司提供的以分布式数据库为核心的一组软件产品,是目前最流行的客户/服务器(Client/Server,C/S)或浏览 ...

  8. HTTP状态码:400\500 错误代码

    一些常见的状态码为: 200 - 服务器成功返回网页404 - 请求的网页不存在503 - 服务不可用详细分解: 1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态代码. 代码  说明100 ...

  9. animation中的steps()逐帧动画

    在我们平时做宽高确定,需要背景图片切换的效果时,我如果用的是一张大的png图片.而且恰好是所有小图都是从左向右排列的,那么 我们只需测量出某一个小图距左侧有多少像素(x),然后我们banckgroun ...

  10. Hibernate对象的状态和映射

    一. Hibernate对象的状态 实体对象的三种状态: 1) 暂态(瞬时态)(Transient)---实体在内存中的自由存在,它与数据库的记录无关. po在DB中无记录(无副本),po和sessi ...