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


上图中 person.sayHi() 是在此时调用的 所以等价于 person.sayHi.call(person) this即为person
fn=person.sayHi() 没有调用 是在fn()s时调用的 在非严格模式下 此时的this即为 全局对象 window
-
call和apply
fn.call(asThis, p1,p2) 是函数的正常调用方式
当你不确定参数的个数时,就使用 apply
fn.apply(asThis, params)
可以看mnd文档
-
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;

网友评论