1. 程式人生 > >call和apply第一個參數為null/undefined,函數this指向全局對象

call和apply第一個參數為null/undefined,函數this指向全局對象

pan 瀏覽器 ie 6 node 嚴格 apply nan pre hive

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

call和apply第一個參數為null/undefined,函數this指向全局對象