Function.prototype.call.apply结合用法
来源:互联网 发布:最新抢火车票软件 编辑:程序博客网 时间:2024/06/10 12:54
昨天在网上看到一个很有意思的js面试题,就跟同事讨论了下,发现刚开始很绕最后豁然开朗,明白过来之后发现还是挺简单的,跟大家分享下!
题目如下:var a = Function.prototype.call.apply(function(a){return a;}, [0,4,3]);alert(a);
分析步骤如下:
1、将Function.prototype.call当成整体,call方法是由浏览器实现的本地方法,是函数类型的内部方法
var a = (Function.prototype.call).apply(function(a){return a;}, [0,4,3]);
2、fun.apply(obj,args)等价于obj.fun(args),这一步是重点,必须理解!
(function(a){return a;}).apply(0,[4,3])
(function(a){return a;}).call(0,4,3)
3、 到这步结果就很明显了,a就是4,alert的结果就是4
这个题目迷惑的点就在于Function.prototype.call,理解好了,就清晰明了了!
- Function.prototype.call.apply结合用法
- JS Function.prototype.apply()和call()
- Function.prototype.apply.call 待解答原理???
- Function.prototype.bind、call与apply方法简介
- 关于Function.prototype.apply.call的一些补充
- prototype-apply and call
- JavaScript:prototype&apply&call
- Function.prototype.apply()
- prototype.js之bind及js apply call用法
- js中继承的几种用法apply,call,prototype
- js中继承的几种用法apply,call,prototype
- apply function and call function
- Function.prototype.bind() ,Function.prototype.call() and function.prototype.apple()
- as3:Function以及call,apply
- call和apply用法
- JavaScript--call( )/apply( )用法
- call 和apply用法
- this, Function.apply 及Function.call
- CMD下查询Mysql中文乱码的解决方法
- XSS第二节,XSS左邻右舍
- “开放·变革” --- 2013腾讯合作伙伴大会
- GWT的国际化
- 开源中国三个平台客户端均已全面开源
- Function.prototype.call.apply结合用法
- Linux下SVN客户端的使用方法
- Leetcode: Binary Tree Zigzag Level Order Traversal
- 心情历练 技术沉淀 生活积淀
- POJ1151(求矩阵的并面积) 离散化
- Struts2.x中获取request,response,session的方式
- Poj 1556 The Doors
- C# 读取Excel文件
- ffmepg 指定网络连接模式UDP还是TCP