Javascript call and apply
来源:互联网 发布:烟台java培训班哪个好 编辑:程序博客网 时间:2024/05/18 15:04
Function.prototype.apply
Calls a function with a given this value and arguments provided as an array.
syntax:
fun.apply(thisArg[, argsArray]).
thisArg
The value of this provided for the call to fun.
argsArray
An array like object
Example:
/* min/max number in an array */var numbers = [5, 6, 2, 3, 7]; /* using Math.min/Math.max apply */var max = Math.max.apply(null, numbers); /* This about equal to Math.max(numbers[0], ...) or Math.max(5, 6, ..) */var min = Math.min.apply(null, numbers); /* vs. simple loop based algorithm */max = -Infinity, min = +Infinity; for (var i = 0; i < numbers.length; i++) { if (numbers[i] > max) max = numbers[i]; if (numbers[i] < min) min = numbers[i];}
The main difference is that apply lets you invoke the function with arguments as an array; call requires the parameters be listed explicitly.
See here and here .
Pseudo syntax:
theFunction.apply(valueForThis, arrayOfArgs)
theFunction.call(valueForThis, arg1, arg2, ...)
- Javascript call and apply
- JavaScript call and apply
- Call and Apply in JavaScript
- javascript apply and call方法的区别
- prototype-apply and call
- call and apply
- call and apply
- js--call and apply
- bind , call and apply
- javascript call apply
- javascript apply vs call
- javascript call() apply()
- JavaScript的call、apply
- javascript call()和apply()
- JavaScript:prototype&apply&call
- JavaScript中的call、apply
- javascript apply call详解
- javascript call和apply
- 理解redo(4)redo log buffer和LGWR
- 晶体管非门电路
- 背包问题九讲 v1.0
- Spring-MVC入门(一):入门实例
- LinkedIn用一幅图告诉你:工程师最想去的10家硅谷创业公司
- Javascript call and apply
- 通过金矿模型介绍动态规划
- Java环境变量配置
- Javascript Exception
- Javascript OOP augmenting with prototype
- 背包总结
- QWT在win7下的安装说明
- 使用QWT产生error LNK2001的原因及解决方案
- Javascript Closure