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 汉字字节判断
Aug 01 Javascript
30个精美的jQuery幻灯片效果插件和教程
Aug 23 Javascript
基于jquery的滚动鼠标放大缩小图片效果
Oct 27 Javascript
js对象关系图 方便dom操作
Mar 18 Javascript
indexOf 和 lastIndexOf 使用示例介绍
Sep 02 Javascript
javascript比较两个日期相差天数的方法
Jul 23 Javascript
jQuery zclip插件实现跨浏览器复制功能
Nov 02 Javascript
Jquery实现select multiple左右添加和删除功能的简单实例
May 26 Javascript
jQuery增加和删除表格项目及实现表格项目排序的方法
May 30 Javascript
JS如何设置iOS中微信浏览器的title
Nov 22 Javascript
JavaScript基于扩展String实现替换字符串中index处字符的方法
Jun 13 Javascript
vue 2.5.1 源码学习 之Vue.extend 和 data的合并策略
Jun 04 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 Try Catch异常测试
2009/03/01 PHP
php写的简易聊天室代码
2011/06/04 PHP
PHP 杂谈《重构-改善既有代码的设计》之五 简化函数调用
2012/05/07 PHP
php cookie 详解使用实例
2016/11/03 PHP
python进程与线程小结实例分析
2018/11/11 PHP
常用的JS验证和函数汇总
2014/12/23 Javascript
javascript 闭包详解
2015/02/15 Javascript
在百度搜索结果中去除掉一些网站的资料(通过js控制不让显示)
2017/05/02 Javascript
阿里大于短信验证码node koa2的实现代码(最新)
2017/09/07 Javascript
vue中使用sessionStorage记住密码功能
2018/07/24 Javascript
详解webpack打包第三方类库的正确姿势
2018/10/20 Javascript
解决node-sass偶尔安装失败的方法小结
2018/12/05 Javascript
微信小程序开发实现的选项卡(窗口顶部/底部TabBar)页面切换功能图文详解
2019/05/14 Javascript
Vue实现随机验证码功能
2020/12/29 Vue.js
举例详解Python中循环语句的嵌套使用
2015/05/14 Python
python 实现在Excel末尾增加新行
2018/05/02 Python
使用Python制作自动推送微信消息提醒的备忘录功能
2018/09/06 Python
Python项目 基于Scapy实现SYN泛洪攻击的方法
2019/07/23 Python
如何在Cloud Studio上执行Python代码?
2019/08/09 Python
python同步两个文件夹下的内容
2019/08/29 Python
PyCharm2018 安装及破解方法实现步骤
2019/09/09 Python
3种适用于Python的疯狂秘密武器及原因解析
2020/04/29 Python
python3.6使用SMTP协议发送邮件
2020/05/20 Python
python如何操作mysql
2020/08/17 Python
HTML5实现页面切换激活的PageVisibility API使用初探
2016/05/13 HTML / CSS
阿迪达斯荷兰官方网站:adidas荷兰
2018/03/16 全球购物
日本最大的购物网站乐天市场国际版:Rakuten Global Market(支持中文)
2020/02/03 全球购物
应届毕业生就业自荐信
2013/10/26 职场文书
大学生如何写自荐信
2014/01/08 职场文书
护理学院专科毕业生求职信
2014/06/28 职场文书
会议简报格式范文
2015/07/20 职场文书
六五普法心得体会2016
2016/01/21 职场文书
如何使用PostgreSQL进行中文全文检索
2021/05/27 PostgreSQL
JavaScript中时间格式化新思路toLocaleString()
2021/11/07 Javascript
python接口测试返回数据为字典取值方式
2022/02/12 Python
Python实现数据的序列化操作详解
2022/07/07 Python