用call调用匿名函数
来源:互联网 发布:邢岫烟 知乎 编辑:程序博客网 时间:2024/06/06 20:24
<html><head><script>function zou() {var animals = [ {species : 'Lion',name : 'King'}, {species : 'Whale',name : 'Fail'} ];for ( var i = 0; i < animals.length; i++) {(function(i) {this.print = function() {alert('#' + i + ' ' + this.species + ': ' + this.name);}this.print();}).call(animals[i], i);}}</script><title>test</title><body> <a href="javascript:zou()">Let's go!</a> </body></html>
The main purpose of the anonymous function here is to add a print function to every object, which is able to print the right index of the object in the array. Passing the object as this value was not strictly necessary, but is done for explanatory purpose.
原文:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FFunction%2Fcall
- 用call调用匿名函数
- 调用匿名函数
- JavaScript匿名函数调用
- 自调用匿名函数
- 自调用匿名函数
- 自调用匿名函数
- setTimeout调用匿名函数
- 函数调用:call
- JavaScript自调用匿名函数
- JS--自调用匿名函数
- 匿名函数自调用(IIFE)
- javascript 自调用匿名函数
- 匿名函数自调用(IIFE)
- JavaScript 自调用匿名函数
- js匿名函数自调用
- js 匿名函数自调用
- 汇编中的函数调用:call
- ExecuteSQL函数 和 call 调用
- 数据库分页查询
- hdu 2112 hdu today
- 函数apply和call的简单例子
- hive安装出现的问题
- hdu 1234开门人和关门人
- 用call调用匿名函数
- 供应链管理柔性系统和单据定制引擎
- c++
- Java regex
- m个数中取n个数的组合
- 把编码为 GB2312 的 NSData 转换为 NSString
- Objective-C中扩展方法、属性和数据成员的解决方案以及方法拦截
- 一个注册表恶意程序
- 前端开发总结