1.call
語法:
call([thisObj[, arg1[, arg2[, [, argN]]]]])
參數:
thisObj: 選擇項。為目前的使用物件。
arg1, arg2, , argN: 選擇項。要傳遞給方法的引數清單。
作用:
call 方法是用來代替另一個物件呼叫方法。此方法可讓您將函式的 this 物件從原始內容變成由 thisObj 所指定的新物件。
如果未提供 thisObj 的話,將使用 global 物件做為 thisObj。
example code:
http://codepen.io/JenHsuan/pen/qrmYxg?editors=1012arrow-up-right
結果
1.一般呼叫時, this指向的是全域物件, window
2.當用call傳入參數時, 會將this指向第一個參數
Last updated 5 years ago