原文 https://thewebjuice.com/es6-arrows/

1 使用es6箭头定义匿名函数

(msg)=>console.log('Hello World')

es5

'use strict';

(function (msg) {
return console.log('Hello World');
});

2 单个参数和多个参数

// Multiple Parameter
(arg1,arg2,arg3,arg4)=>{
return arg1+arg2+arg3+arg4
} // Single Parameter
(arg1)=>{
return arg1
}

es5

"use strict";

// Multiple Parameter
(function (arg1, arg2, arg3, arg4) {
return arg1 + arg2 + arg3 + arg4;
}); // Single Parameter
(function (arg1) {
return arg1;
});

3定义闭包

 // Single Line Closure
var SayHello=(hello)=>console.log(hello) // Multi Line Closure
var SayHelloAgain=(hello)=>{
console.log('This is a multiline Closure')
console.log(hello)
} // Calling the Two above Closure
SayHello('Hey I am ES6 Arrow')
SayHelloAgain('Heya Again!!!');

es5

 'use strict';

 // Single Line Closure
var SayHello = function SayHello(hello) {
return console.log(hello);
}; // Multi Line Closure
var SayHelloAgain = function SayHelloAgain(hello) {
console.log('This is a multiline Closure');
console.log(hello);
}; // Calling the Two above Closure
SayHello('Hey I am ES6 Arrow');
SayHelloAgain('Heya Again!!!');

4  Literal Syntax

 var createObject = (x,y,color)=>({x:x,y:y,z:z})

es5

 "use strict";

 var createObject = function createObject(x, y, color) {
return { x: x, y: y, z: z };
};

javascript箭头函数的更多相关文章

  1. 轻松学习 JavaScript——第 6 部分:JavaScript 箭头函数

    JavaScript箭头函数是ECMAScript 6中引入的编写函数表达式的一种简便方法.通常,在JavaScript中,可以通过两种方式创建函数: 函数语句. 函数表达式. 可以如下所示创建函数语 ...

  2. JavaScript箭头函数中的this详解

    前言 箭头函数极大地简化了this的取值规则. 普通函数与箭头函数 普通函数指的是用function定义的函数: var hello = function () { console.log(" ...

  3. 动态导航栏和JavaScript箭头函数

    动态导航栏和JavaScript箭头函数 今天我们来写一下动态的导航栏,并且学一下JavaScript的箭头函数等相关问题. 样式如下所示: html中执行代码如下所示: <!DOCTYPE h ...

  4. JavaScript箭头函数 和 generator

    箭头函数: 用箭头定义函数........           var fun = x=>x*x alert(fun(2))            //单参数   var fun1 = ()=& ...

  5. javascript箭头函数把函数给简写了[0403]

    箭头函数把函数给简写了[0403]        我不是很喜欢箭头函数,总觉得它让原本就不那么严谨的js更加不严谨了,所以有时候看js程序也是一件很头痛的事情,不过在ES6中加入了这么一个新的方法,已 ...

  6. JavaScript 箭头函数

    ES6新标准增加了一种新的函数,箭头函数. x=>x*x 相当于: function (x){ return x*x; } 如果参数不是一个,就需要用括号()括起来: // 两个参数:var t ...

  7. javascript 箭头函数的使用 初学者必看

    为了保证可读性,本文采用意译而非直译.另外,本文版权归原作者所有,翻译仅用于学习. 本文我们介绍箭头(arrow)函数的优点. 更简洁的语法我们先来按常规语法定义函数: 1 2 3 4 5 funct ...

  8. JavaScript箭头函数(Lambda表达式)

    箭头函数也叫lambda表达式 据说其主要意图是定义轻量级的内联回调函数 栗有: 1 var arr = ["wei","ze","yang" ...

  9. JavaScript 箭头函数(Lambda表达式)

    Lambda表达式(箭头函数)用于表示一个函数,所以它和函数一样,也拥有参数.返回值.函数体,但它没有函数名,所以Lambda表达式相当于一个匿名函数. 使用方法: ()=>{} 小括号里放参数 ...

随机推荐

  1. plsql导入导出表数据

    导出表结构: Tools(工具)-->Export User Objects(导出用户对象) -->选择要导出的表(包括Sequence等)-->.sql文件,导出的都为sql文件 ...

  2. [转载]SQL Server行列转换实现

    可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P 完整语法: table_source PIVOT( 聚合函数(value_ ...

  3. svn: Can't convert string from 'UTF-8' to native encoding: 解决办法

    在linux中,svn co 或 svn up 时有中文文件名的文件的话,可能会报下面的错: [root@linkea-dev-srv1 ~]# svn upsvn: Can't convert st ...

  4. sql查询优化--数字转换字符串字段

    SELECT top 1 pt.* FROM t1where id='20180731223014' SELECT top 1 pt.* FROM t1where id='0180731223014 ...

  5. C# skip 重试执行代码段

    var retryTimes = 5; //重试次数 int times = 0;  skip:              //代码段开始 //处理逻辑 var result=false ;   // ...

  6. MaxScript粒子流塌陷

    也是帮网友写的.不过最后没用上.哈哈. targetPF = $ startTime = AnimationRange.Start.Frame endTime = AnimationRange.End ...

  7. LESS+to+MCSS

    此文已由作者郑海波授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验 一.前言 虽然首页没有开始做,昨天仍决定将[MCSS](https://github.com/NetEaseW ...

  8. WPF Adorner 在TabControl切换TabItem时消失

    错误的截图: 一开始以为是MVVM绑定的代码中出现了问题,但是通过断点追踪并没有发现问题. 通过通过VS的实时可视化树发现问题:切换Item时Adorner会在AdornerLayer直接消失.届时怀 ...

  9. ClamAV学习【8】——64位Windows7下编译运行实践

    之前用SourceInsight静态分析了ClamAV引擎源码,现在打算开始动态研究下.不过出师不利,一开始就遇到纠结的问题,能力还有待提高. 从官网下了一个VS2005工程的源码包(http://d ...

  10. B - Bridging signals (LIS)

    点击打开链接 B - Bridging signals 'Oh no, they've done it again', cries the chief designer at the Waferlan ...