此函數使用 args 參數指定的參數調用目標函數。
用法
此處給出的語法適用於 apply(),其中,
target表示要調用的目標函數
thisArgument是為目標調用提供的 this 值。
argumentsList是一個 array-like 對象,指定應使用哪個目標調用的參數。
Reflect.apply(target, thisArgument, argumentsList)
示例
下麵的示例定義了一個計算並返回矩形麵積的函數。
<script>
const areaOfRectangle = function(width,height){
return `area is ${width*height} ${this.units}`
}
const thisValue = {
units:'Centimeters'
}
const argsList = [10,20]
const result = Reflect.apply(areaOfRectangle,thisValue,argsList)
console.log(result)
</script>
上麵代碼的輸出將如下麵提到的那樣——
area is 200 Centimeters
相關用法
- ES6 Reflect.set()用法及代碼示例
- ES6 Reflect.construct()用法及代碼示例
- ES6 Reflect.has()用法及代碼示例
- ES6 Reflect.get()用法及代碼示例
- ES6 RegExp split()用法及代碼示例
- ES6 RegExp replace()用法及代碼示例
- ES6 RegExp exec()用法及代碼示例
- ES6 RegExp test()用法及代碼示例
- ES6 RegExp toString()用法及代碼示例
- ES6 RegExp search()用法及代碼示例
- ES6 Array every()用法及代碼示例
- ES6 Array reduceRight()用法及代碼示例
- ES6 handler.set()用法及代碼示例
注:本文由純淨天空篩選整理自 ES6 - Reflect.apply()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。