
this
this必须是对象,因为this是函数和对象的羁绊


call / apply
fn.call(asThis, p1,p2) 是函数的正常调用方式
当你不确定参数的个数时,就使用 apply
fn.apply(asThis, params)
bind
call 和 apply 是直接调用函数,而 bind 则是返回一个新函数(并没有调用原来的函数),这个新函数会 call 原来的函数,call 的参数由你指定。

要让里面的this.onClick的this指向view,可以采用下面方法:


return
每个函数都有 return
如果你不写 return,就相当于写了 return undefined
高阶函数:
在数学和计算机科学中,高阶函数是至少满足下列一个条件的函数:
接受一个或多个函数作为输入:forEach sort map filter reduce
输出一个函数:lodash.curry
不过它也可以同时满足两个条件:Function.prototype.bind
柯里化:将 f(x,y) 变成 f(x=1)(y) 或 f(y=1)x
返回函数的函数
回调
名词形式:被当做参数的函数就是回调
动词形式:调用这个回调
注意回调跟异步没有任何关系
接受一个函数和多个函数的函数返回一个函数就是高阶函数;
将函数作为参数的函数就是回调;
接受一个函数去除了其中变量为柯里化;


箭头函数
没有this,this指向的是最近的this;
箭头函数没办法指定this,永远都是把外面的this当作里面的this;

网友评论