call和apply第一个参数为null/undefined,函数this指向全局对象

call和apply第一个参数为null/undefined,函数this指向全局对象,在浏览器中是window,在node中是global

在严格模式中(ie 6/7/8/9 除外),传入null/undefined,this不指向全局对象,而是null/undefined本身

'use strict'

function func(){
  console.log(this);
}

func.call(null); // null
func.apply(undefined); // undefined

 

 


参考:http://www.cnblogs.com/snandy/archive/2012/03/01/2373243.html

posted @ 2018-10-11 10:33  全玉  阅读(238)  评论(0编辑  收藏  举报