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 相关文章推荐
JavaScript CSS修改学习第五章 给“上传”添加样式
Feb 19 Javascript
点击页面其它地方隐藏该div的两种思路
Nov 18 Javascript
jquery搜索框效果实现方法
Jan 16 Javascript
对JavaScript中this指针的新理解分享
Jan 31 Javascript
深入理解JavaScript系列(31):设计模式之代理模式详解
Mar 03 Javascript
JavaScript实现的字符串replaceAll函数代码分享
Apr 02 Javascript
jquery ajax结合thinkphp的getjson实现跨域的方法
Jun 06 Javascript
jQuery与js实现颜色渐变的方法
Dec 30 Javascript
微信小程序动态增加按钮组件
Sep 14 Javascript
JavaScript箭头函数中的this详解
Jun 19 Javascript
jQuery操作事件完整实例分析
Jan 10 jQuery
js基于div丝滑实现贝塞尔曲线
Sep 23 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 数组教程 定义数组
2009/10/23 PHP
php 空格,换行,跳格使用说明
2009/12/18 PHP
php中$_REQUEST、$_POST、$_GET的区别和联系小结
2011/11/23 PHP
PHP高自定义性安全验证码代码
2011/11/27 PHP
PHP中开启gzip压缩的2种方法
2015/01/31 PHP
PHP中Http协议post请求参数
2015/11/02 PHP
PHP调试的强悍利器之PHPDBG
2016/02/22 PHP
ExtJs使用IFrame的实现代码
2010/03/24 Javascript
图解JavaScript中的this关键字
2020/05/28 Javascript
Bootstrap组件(一)之菜单
2016/05/11 Javascript
使用AngularJS2中的指令实现按钮的切换效果
2017/03/27 Javascript
JS关于刷新页面的相关总结
2018/05/09 Javascript
Vue插件打包与发布的方法示例
2018/08/20 Javascript
Node.js 的 GC 机制详解
2019/06/03 Javascript
jquery弹窗时禁止body滚动条滚动的例子
2019/09/21 jQuery
nodejs制作小爬虫功能示例
2020/02/24 NodeJs
[01:37]TI4西雅图DOTA2前线报道 VG拿下首胜教练357给出获胜秘诀
2014/07/10 DOTA
[00:58]2016年国际邀请赛勇士令状宣传片
2016/06/01 DOTA
[40:03]RNG vs VG 2019国际邀请赛小组赛 BO2 第二场 8.15
2019/08/17 DOTA
Python中集合类型(set)学习小结
2015/01/28 Python
在Python的Flask框架下使用sqlalchemy库的简单教程
2015/04/09 Python
Python黑魔法Descriptor描述符的实例解析
2016/06/02 Python
详解Python开发中如何使用Hook技巧
2017/11/01 Python
Python编程使用*解包和itertools.product()求笛卡尔积的方法
2017/12/18 Python
Python读取properties配置文件操作示例
2018/03/29 Python
python调用Matplotlib绘制分布点并且添加标签
2018/05/31 Python
完美解决在oj中Python的循环输入问题
2018/06/25 Python
python3.5基于TCP实现文件传输
2020/03/20 Python
详解Python在使用JSON时需要注意的编码问题
2019/12/06 Python
Python3+PyCharm+Django+Django REST framework配置与简单开发教程
2021/02/16 Python
CSS3中的content属性使用示例
2015/07/20 HTML / CSS
HTML5中input输入框默认提示文字向左向右移动的示例代码
2020/09/10 HTML / CSS
维多利亚的秘密阿联酋官网:Victoria’s Secret阿联酋
2019/12/07 全球购物
一份文言文检讨书
2014/09/13 职场文书
2014乡镇机关党员个人对照检查材料思想汇报
2014/10/09 职场文书
SQL 窗口函数实现高效分页查询的案例分析
2021/05/21 SQL Server