JavaScript的Function详细


Posted in Javascript onNovember 14, 2006

Function (Built-in Object)
Function (?戎?ο?
Function is the object from which JavaScript functions are derived. Functions are first-class data types in JavaScript, so they may be assigned to variables and passed to functions as you would any other piece of data. Functions are, of course, reference types.

The Function object provides both static properties like length and properties that convey useful information during the execution of the function, for example, the arguments[] array.

Constructor
var instanceName = new Function([arg1 [, arg2 [, ...]] ,] body); 

The body parameter is a string containing the text that makes up the body of the function. The optional argN's are the names of the formal parameters the function accepts. For example:

var myAdd = new Function("x", "y", "return x + y");
var sum = myAdd(17, 34);

Properties

arguments[] An implicitly filled and implicitly available (directly usable as "arguments" from within the function) array of parameters that were passed to the function. This value is null if the function is not currently executing. (IE4+ (JScript 2.0+), MOZ, N3+ (JavaScript 1.1+), ECMA Edition 1)

arguments.callee Reference to the current function. This property is deprecated. (N4+, MOZ, IE5.5+)

arguments.caller Reference to the function that invoked the current function. This property is deprecated. (N3, IE4+)

arguments.length The number of arguments that were passed to the function. (IE4+ (JScript 2.0+), MOZ, N3+ (JavaScript 1.1+), ECMA Edition 1)

arity Numeric value indicating how many arguments the function expects. This property is deprecated. (N4+, MOZ)

caller Reference to the function that invoked the current function or null if called from the global context. (IE4+ (JScript 2.0+), MOZ, N3+)

constructor Reference to the constructor object that created the object. (IE4+ (JScript 2.0+), N3+ (JavaScript 1.1+), ECMA Edition 1)

length The number of arguments the function expects to be passed. (IE4+ (JScript 2.0+), N3+ (JavaScript 1.1+), ECMA Edition 1)

prototype Reference to the object's prototype. (IE4+ (JScript 2.0+), N3+ (JavaScript 1.1+), ECMA Edition 1)

Methods
apply(thisArg [, argArray]) Invokes the function with the object referenced by thisArg as its context (so references to this in the function reference thisArg). The optional parameter argArray contains the list of parameters to pass to the function as it is invoked. (IE5.5+ (JScript 5.5+), N4.06+ (JavaScript 1.3+), MOZ, ECMA Edition 3) 

call(thisArg [, arg1 [, arg2 [, ...]]]) Invokes the function with the object referenced by thisArg as its context (so references to this in the function reference thisArg). The optional parameters argN are passed to the function as it is invoked. (IE5.5+ (JScript 5.5+), N4.06+ (JavaScript 1.3+), MOZ, ECMA Edition 3)

toString() Returns the string version of the function source. The body of built-in and browser objects will typically be represented by the value "[native code]". (IE4+ (JScript 2.0+), N3+ (JavaScript 1.1+), MOZ, ECMA Edition 1)

valueOf() Returns the string version of the function source. The body of built-in and browser objects will typically be represented by the value "[native code]". (IE4+ (JScript 2.0+), N3+ (JavaScript 1.1+), MOZ, ECMA Edition 1)

Support
Supported in IE4+ (JScript 2.0+), N3+ (JavaScript 1.1+), MOZ, ECMAScript Edition 1.

Notes
General examples of functions are found throughout the book, but see Chapter 5 for examples of the advanced aspects of functions and the Function object.

Javascript 相关文章推荐
地址栏传递中文参数乱码在js里用escape转码
Aug 28 Javascript
angularJS结合canvas画图例子
Feb 09 Javascript
jQuery插件实现大图全屏图片相册
Mar 14 Javascript
SpringMVC框架下JQuery传递并解析Json格式的数据是如何实现的
Dec 10 Javascript
去除字符串左右两边的空格(实现代码)
May 12 Javascript
JavaScript和jquery获取父级元素、子级元素、兄弟元素的方法
Jun 05 Javascript
基于jQuery的ajax方法封装
Jul 14 Javascript
jQuery Easyui Datagrid实现单行的上移下移及保存移动的结果
Aug 15 Javascript
jQuery无缝轮播图代码
Dec 22 Javascript
jQuery实现的粘性滚动导航栏效果实例【附源码下载】
Oct 19 jQuery
微信小程序常用赋值方法小结
Apr 30 Javascript
JavaScript find()方法及返回数据实例
Apr 30 Javascript
取得父标签
Nov 14 #Javascript
多广告投放代码 推荐
Nov 13 #Javascript
js类 from qq
Nov 13 #Javascript
一段非常简单的让图片自动切换js代码
Nov 10 #Javascript
类似框架的js代码
Nov 09 #Javascript
二级域名转向类
Nov 09 #Javascript
JavaScript的面向对象(一)
Nov 09 #Javascript
You might like
php 格式化数字的时候注意数字的范围
2010/04/13 PHP
PHP面向对象程序设计之接口的继承定义与用法详解
2018/12/20 PHP
Cookie跨域问题解决方案代码示例
2020/11/24 PHP
基于jQuery的弹出消息插件 DivAlert之旅(一)
2010/04/01 Javascript
使用jquery为table动态添加行的实现代码
2011/03/30 Javascript
js修改input的type属性及浏览器兼容问题探讨与解决
2013/01/23 Javascript
js中复制行和删除行的操作实例
2013/06/25 Javascript
js简单实现HTML标签Select联动带跳转
2013/10/23 Javascript
AngularJS内置指令
2015/02/04 Javascript
vue router仿天猫底部导航栏功能
2017/10/18 Javascript
vuex actions传递多参数的处理方法
2018/09/18 Javascript
微信小程序可滑动月日历组件使用详解
2019/10/21 Javascript
Vue修改项目启动端口号方法
2019/11/07 Javascript
浅析JavaScript中的事件委托机制跟深浅拷贝
2021/01/20 Javascript
[37:45]2014 DOTA2国际邀请赛中国区预选赛5.21 DT VS Orenda
2014/05/22 DOTA
[01:19:54]DOTA2上海特级锦标赛主赛事日 - 2 败者组第二轮#1Alliance VS EHOME
2016/03/03 DOTA
python实现超简单端口转发的方法
2015/03/13 Python
深入理解Python中装饰器的用法
2016/06/28 Python
python+matplotlib实现礼盒柱状图实例代码
2018/01/16 Python
python正则表达式面试题解答
2020/04/28 Python
python使用tkinter实现简单计算器
2018/01/30 Python
python 内置模块详解
2019/01/01 Python
python使用for循环计算0-100的整数的和方法
2019/02/01 Python
appium+python adb常用命令分享
2020/03/06 Python
python Scrapy爬虫框架的使用
2021/01/21 Python
css3 旋转按钮 使用CSS3创建一个旋转可变色按钮
2012/12/31 HTML / CSS
您附近的水疗和健康场所:Spafinder(美国)
2019/07/05 全球购物
俄罗斯首家面向中国消费者的一站式购物网站:Wruru
2020/05/08 全球购物
酷瑞网络科技面试题
2012/03/30 面试题
小学学校评估方案
2014/06/08 职场文书
工会工作先进事迹
2014/08/18 职场文书
2014年宣传思想工作总结
2014/12/10 职场文书
上班迟到检讨书
2015/05/06 职场文书
上帝也疯狂观后感
2015/06/09 职场文书
婚礼长辈答谢词
2015/09/29 职场文书
导游词之湖州-太湖
2019/10/11 职场文书