Last active
November 30, 2017 06:21
-
-
Save googya/1030b585f7c8877620942c50ce36ef83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function doubleAfter2Seconds(x) { | |
| return new Promise((resolve, reject) => { | |
| resolve(x * 2) | |
| }, 2000) | |
| } | |
| async function addAsync(x) { | |
| const a = doubleAfter2Seconds(10); | |
| const b = doubleAfter2Seconds(20); | |
| const c = doubleAfter2Seconds(30); | |
| return x + (await a) + (await b) + (await c); | |
| } | |
| addAsync(10).then(e => console.log(e)) | |
| function foo() { | |
| return () => { | |
| return () => { | |
| return () => { | |
| console.log("id:", this.id); | |
| }; | |
| }; | |
| }; | |
| } | |
| var f = foo.call({id: 1}); | |
| var t1 = f.call({id: 2})()(); | |
| var t2 = f().call({id: 3})(); | |
| var t3 = f()().call({id: 4}); | |
| // from [关于箭头函数this的理解几乎完全是错误的](https://github.com/ruanyf/es6tutorial/issues/150) | |
| // 箭头函数与普通函数的差异, 箭头函数的执行环境是, 创建箭头函数所在的对象(lexical scoping, 从源代码中即可知道环境是什么, global 环境, 还是其他对象) | |
| function a(x200){ | |
| return (x300) => { | |
| return (x400) => { | |
| return this.x; | |
| } | |
| } | |
| } | |
| function a(x200){ | |
| return function(x300) { | |
| return (x400) => { | |
| return this.x; | |
| } | |
| } | |
| } | |
| function a(){ | |
| return function(){ | |
| return function(){ | |
| return this.x; | |
| } | |
| } | |
| } | |
| x = 100 | |
| console.log(a.call({x: 200}).call({x: 300}).call({x: 400})) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使用 ramda 重写 https://github.com/getify/Functional-Light-JS/blob/master/manuscript/ch1.md 中的例子