###1 The Method Invocation Pattern
obj.action()
this -> obj
###2 The Function Invocation Pattern
fun()
this -> 向上作用域查找 this, 直到最后的 global object (window
object in browser env, module.exports
in node env)
###3 The Constructor Invocation Pattern
new Foo()
this -> the new instance object
###4 The Apply Invocation Pattern // invoke function
fun.apply(this, params array)
fun.call(this, arg1, arg2)
// return a new function
fun.bind(this, arg1, arg2)
this -> dynamic by apply()
and call()
, bind()
first param.
const fun = () => console.log(this);
this -> auto bind this to function write scope, not invoke scope.
http://bdcampbell.net/javascript/book/javascript_the_good_parts.pdf
Chapter 4: Functions