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. 03 java 基础:注释 关键字 标识符 JShell

    Java 10 中已有 Jshell 工具,方便用户在其中直接输入相关 java 代码. 注释:java 中分为单行注释 //   多行注释 /*   */   文档注释 /**  */ 关键字:在 ...

  2. sprint定时任务执行两次

    我这里遇到的是tomcat问题,把appBase设置为空 <Host name="localhost" appBase="" unpackWARs=&qu ...

  3. 转:Spring学习笔记---Spring Security登录页

    转:http://axuebin.com/blog/2016/06/21/spring-security/?utm_source=tuicool&utm_medium=referral. 提示 ...

  4. NBUT 1218 You are my brother

    $dfs$. 记录一下每一个节点的深度就可以了. #include<cstdio> #include<cstring> #include<cmath> #inclu ...

  5. 牛刀小试之Django二

    model 到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用 MySQLdb 来连接数据库,并编写数据访问层代码 业务逻辑层去调用数据访问层执行 ...

  6. shell 执行结果赋给变量

    #将pwd的执行结果放到变量value中保存, value=$(pwd) 另一种方法: value=`pwd`

  7. Redux 和 Redux thunk 理解

    1: state 就像 model { todos: [{ text: 'Eat food', completed: true }, { text: 'Exercise', completed: fa ...

  8. 内存分哪些区 C++,ios,java

    韩梦飞沙 yue31313 韩亚飞 han_meng_fei_sha 313134555@qq.com C/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)—由编译器自动分配释放,存 ...

  9. bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛

    1734: [Usaco2005 feb]Aggressive cows 愤怒的牛 Description Farmer John has built a new long barn, with N ...

  10. python基础之数据类型,交互,格式化输出,基本运算符

    数据类型 1.什么是数据类型? 变量值才是我们存的数据,所以数据类型指的是变量值的种类 2.为何数据要分类? 变量值是用来保存现实世界中的状态的,那么针对不同的状态,就应该用不同类型的数据去表示 3. ...