参数的求值策略: var x = 1; function f(m){ return m * 2; } f(x + 5); // x +5 在何时运算? 1.传值调用: var x = 1; function f(m){ return m * 2; } f(6); // 将值先计算出来再作为参数传入函数.C 语言采用这种策略 2.传名调用 var x = 1; function f(m){ return m * 2; // (x + 5) * 2.参数不求值,传到函数中,在函数中进行运算求值.JS…
转: ES6异步编程:Thunk函数的含义与用法 参数的求值策略 Thunk函数早在上个世纪60年代就诞生了. 那时,编程语言刚刚起步,计算机学家还在研究,编译器怎么写比较好.一个争论的焦点是"求值策略",即函数的参数到底应该何时求值. var x = 1; function f(m){ return m * 2; } f(x+5); 上面代码先定义函数 f,然后向它传入表达式 x + 5 .请问,这个表达式应该何时求值? 一种意见是"传值调用"(call by v…
转: ES6异步编程: co函数库的含义与用法 co 函数库是著名程序员 TJ Holowaychuk 于2013年6月发布的一个小工具,用于 Generator 函数的自动执行. 比如,有一个 Generator 函数,用于依次读取两个文件. var gen = function* (){ var f1 = yield readFile('./foo.txt'); var f2 = yield readFile('./bar.txt'); console.log(f1.toString());…
Thunk https://en.wikipedia.org/wiki/Thunk In computer programming, a thunk is a subroutine used to inject an additional calculation into another subroutine. Thunks are primarily used to delay a calculation until its result is needed, or toinsert oper…
redux-thunk https://github.com/reduxjs/redux-thunk Why Do I Need This? Thunks are the recommended middleware for basic Redux side effects logic, including complex synchronous logic that needs access to the store, and simple async logic like AJAX requ…