Normally, we can set default value for function param:

//Here use "Hello" as default param
var receive =function(message="Hello", handle){
handler(message);
} receive("Come", function(message){
console.log(message + ", "+ "John");
});

What we can do is use function as a default param:

var receive =function(message="Hello", handler=function(message){
console.log(message + ", "+ "John");
}){
handler(message);
} receive("Come"); //Come, John

Then we can use => to refactor the code:

var receive =function(message="Hello", handler= message => console.log(message + ", "+ "John")){
handler(message);
} receive("Go"); //Go, John

It will be crazy: (do not use this, cannot be understood)

let receive = (message="Hello", handler= message => console.log(message + ", "+ "John")) => handler(message)

receive(); //Hello John

[ES6] 07. Default Value for function param的更多相关文章

  1. ES6 Class vs ES5 constructor function All In One

    ES6 Class vs ES5 constructor function All In One ES6 类 vs ES5 构造函数 https://developer.mozilla.org/en- ...

  2. es6 模块编译 *** is not function

    今天学习vuejs,里面用到了es6的写法,遇到了一个很怪的问题,不知道有人遇到么. 安装的模块引用:import Vue from 'vue';(注意,Vue处没有{},如果加上这个就报错Uncau ...

  3. 深入学习Java8 Lambda (default method, lambda, function reference, java.util.function 包)

    Java 8 Lambda .MethodReference.function包 多年前,学校讲述C#时,就已经知道有Lambda,也惊喜于它的方便,将函数式编程方式和面向对象式编程基于一身.此外在使 ...

  4. es6语法中的arrow function=>

    (x) => x + 相当于 function(x){ ; }; var ids = this.sels.map(item => item.id).join() var ids = thi ...

  5. ES6 new syntax of Arrow Function

    Arrow Function.md Arrow Functions The basic syntax of an arrow function is as follows var fn = data ...

  6. ES6 箭头函数(arrow function)

    例行声明:接下来的文字内容全部来自 Understanding ECMAScript 6,作者是Nicholas C.Zakas,也就是大名鼎鼎的Professional JavaScript for ...

  7. Es6 export default 的用法

    export 之后加上default意指默认接口的意思,在一个文件里面默认的只能有一个 其区别就是{} 在export中 引入需要用{}来盛放 //这是设置入口var a='my name is xi ...

  8. ES6 export default 和 export 的区别

    export default 和 export 区别: 1.export与export default均可用于导出常量.函数.文件.模块等 2.你可以在其它文件或模块中通过import+(常量 | 函 ...

  9. [ES6] Function Params

    1. Default Value of function param: The function displayTopicsPreview() raises an error on the very ...

随机推荐

  1. 走进 Akka.NET

    官方文档:https://getakka.net/index.html 官网:https://petabridge.com/ 一.Akka.NET 是什么? Akka 是一个构建高并发.分布式和弹性消 ...

  2. nodejs里的express自动刷新gulp-express使用【转载】

    搬运自[http://blog.csdn.net/zhu_free/article/details/51476525] gulp-express实现实时刷新 本来使用gulp-connect可以创建本 ...

  3. mysql-错误备查

    转载请注明:仰望大牛的小清新   http://www.cnblogs.com/luruiyuan/ 这个文章的主要目的是总结自己的作死经历,以备查找 1. Ubuntu MySQL 服务的启动/停止 ...

  4. Envious Exponents

    问题 E: Envious Exponents 时间限制: 1 Sec  内存限制: 128 MB提交: 321  解决: 53[提交] [状态] [讨论版] [命题人:] 题目描述 Alice an ...

  5. 【BZOJ 1057】 1057: [ZJOI2007]棋盘制作

    1057: [ZJOI2007]棋盘制作 Description 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源 于易经的思想,棋盘是一个8*8大小的 ...

  6. Codeforces 741B Arpa's weak amphitheater and Mehrdad's valuable Hoses

    [题目链接] http://codeforces.com/problemset/problem/741/B [题目大意] 给出一张图,所有连通块构成分组,每个点有价值和代价, 要么选择整个连通块,要么 ...

  7. 【找规律】【DFS】Gym - 101174H - Pascal's Hyper-Pyramids

    二维下,如果把杨辉三角按照题目里要求的那样摆放,容易发现,第i行第j列的数(从0开始标号)是C(i+j,i)*C(j,j). 高维下也有类似规律,比如三维下,最后一层的数其实是C(i+j+k,i)*C ...

  8. python安装BeautifulSoup

    1.先下载pip https://pypi.python.org/pypi/pip 安装pip cd到路径 python setuo.py install 2.添加目录到环境变量中 xxx\Pytho ...

  9. 1.创建spring cloud父工程和子模块

    创建父工程 idea创建父工程 idea创建一个工程.父工程管理公共资源 添加子模块 选择添加到父工程里面spring_cloud_parent 相应的子模块添加到父工程的pom.xml文件里

  10. Problem B: 判断回文字符串

    #include<stdio.h> #include<string.h> int huiwen(char *str) //定义回文函数 { //char ch[100]; in ...