[ES6] 07. Default Value for function param
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的更多相关文章
- 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- ...
- es6 模块编译 *** is not function
今天学习vuejs,里面用到了es6的写法,遇到了一个很怪的问题,不知道有人遇到么. 安装的模块引用:import Vue from 'vue';(注意,Vue处没有{},如果加上这个就报错Uncau ...
- 深入学习Java8 Lambda (default method, lambda, function reference, java.util.function 包)
Java 8 Lambda .MethodReference.function包 多年前,学校讲述C#时,就已经知道有Lambda,也惊喜于它的方便,将函数式编程方式和面向对象式编程基于一身.此外在使 ...
- es6语法中的arrow function=>
(x) => x + 相当于 function(x){ ; }; var ids = this.sels.map(item => item.id).join() var ids = thi ...
- ES6 new syntax of Arrow Function
Arrow Function.md Arrow Functions The basic syntax of an arrow function is as follows var fn = data ...
- ES6 箭头函数(arrow function)
例行声明:接下来的文字内容全部来自 Understanding ECMAScript 6,作者是Nicholas C.Zakas,也就是大名鼎鼎的Professional JavaScript for ...
- Es6 export default 的用法
export 之后加上default意指默认接口的意思,在一个文件里面默认的只能有一个 其区别就是{} 在export中 引入需要用{}来盛放 //这是设置入口var a='my name is xi ...
- ES6 export default 和 export 的区别
export default 和 export 区别: 1.export与export default均可用于导出常量.函数.文件.模块等 2.你可以在其它文件或模块中通过import+(常量 | 函 ...
- [ES6] Function Params
1. Default Value of function param: The function displayTopicsPreview() raises an error on the very ...
随机推荐
- highcharts高级画图柱状图和折线图
折线图一枚 $("#z_line").highcharts({ chart: { type: 'line' }, credits: { enabled: false // 禁用版权 ...
- 【剑指offer】面试题 28. 对称的二叉树
面试题 28. 对称的二叉树 题目描述 题目:请实现一个函数,用来判断一颗二叉树是不是对称的.注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的. 解答过程 给定一个二叉树,检查它是否是镜像 ...
- 选择排序(SelectionSort)
http://blog.csdn.net/magicharvey/article/details/10274765 算法描述 选择排序是一种不稳定排序.选择排序每次交换一对元素,它们当中至少有一个将被 ...
- python版GetTickCount()
time.clock() return the current processor time as a floating point number expressed in seconds. 即返回一 ...
- Python 一条语句如何在多行显示的问题
在做python学习的时候,我照着pdf,敲代码,遇到一大难题: return render_to_response('index.html',{'title':'my page','user':us ...
- 633. Sum of Square Numbers【Easy】【双指针-是否存在两个数的平方和等于给定目标值】
Given a non-negative integer c, your task is to decide whether there're two integers a and bsuch tha ...
- 反编译apk 修改 合成
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 反编译apk帮助文档 准备工具 dex2jar(dex转换jar工具),下载地址: ht ...
- luogu P1016 旅行家的预算
题目描述 一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离D1.汽车油箱的容量C(以升为单位).每升汽油能行驶的距离D2.出发点每升汽油价格P和沿 ...
- 【推导】Codeforces Round #410 (Div. 2) C. Mike and gcd problem
如果一开始就满足题意,不用变换. 否则,如果对一对ai,ai+1用此变换,设新的gcd为d,则有(ai - ai+1)mod d = 0,(ai + ai+1)mod d = 0 变化一下就是2 ai ...
- python学习第九十天:vue补习2
Vue 八.重要指令 v-bind <!-- 值a --> <div v-bind:class='"a"'></div> <!-- 变量a ...