標籤:style blog http color os java 使用 io for
轉載:http://msdn.microsoft.com/zh-cn/library/4zc42wh1(v=vs.94).aspx
寫在前面:與call方法類似
調用函數,並用指定對象替換函數的 this 值,同時用指定數組替換函數的參數。
apply([thisObj[,argArray]])
參數
thisObj
可選。 要用作 this 對象的對象。
argArray
可選。 要傳遞到函數的一組參數。
備忘
如果 argArray 不是有效對象,則會出現“應為對象”錯誤。
如果既未提供 argArray 也未提供 thisObj,則原始 this 對象將被用作 thisObj 且不會傳遞任何參數。
樣本
下面的代碼示範如何使用 apply 方法。
1 function callMe(arg1, arg2){ 2 console.log(‘this value: ‘+ this); 3 for (var i in callMe.arguments) { 4 console.log(‘arguments: ‘+ callMe.arguments[i]) 5 } 6 } 7 8 callMe(1, 2); 9 // this value: [object Window]10 // arguments: 111 // arguments: 2 12 13 callMe.apply(‘a‘, [‘b‘, ‘c‘])14 // this value: a15 // arguments: b16 // arguments: c
要求
在以下文檔模式中受支援:Quirks、Internet Explorer 6 標準模式、Internet Explorer 7 標準模式、Internet Explorer 8 標準模式、Internet Explorer 9 標準模式、Internet Explorer 10 標準模式和 Internet Explorer 11 標準模式。此外,也在市集應用(Windows 8 和 Windows Phone 8.1)中受支援。
apply 方法 (Function) (JavaScript)