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重建星际争霸
Dec 22 Javascript
JAVASCRIPT style 中visibility和display之间的区别
Jan 22 Javascript
jQuery EasyUI API 中文文档 - ComboTree组合树
Oct 11 Javascript
浏览器页面区域大小的js获取方法
Sep 21 Javascript
JS两个数组比较,删除重复值的巧妙方法(推荐)
Jun 03 Javascript
百度多文件异步上传控件webuploader基本用法解析
Nov 07 Javascript
微信小程序 开发经验整理
Feb 15 Javascript
Bootstrap modal 多弹窗之叠加引起的滚动条遮罩阴影问题
Feb 27 Javascript
微信小程序tabBar模板用法实例分析【附demo源码下载】
Nov 28 Javascript
浅谈对于react-thunk中间件的简单理解
May 01 Javascript
vue实现滑动解锁功能
Mar 03 Vue.js
vue整合百度地图显示指定地点信息
Apr 06 Vue.js
取得父标签
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/05/16 PHP
一个PHP的远程图片抓取函数分享
2013/09/25 PHP
ThinkPHP写数组插入与获取最新插入数据ID实例
2014/11/03 PHP
教你在header中隐藏php的版本信息
2016/08/10 PHP
php数据库的增删改查 php与javascript之间的交互
2017/08/31 PHP
Avengerls vs Newbee BO3 第二场2.18
2021/03/10 DOTA
js下关于onmouseout、事件冒泡的问题经验小结
2010/12/09 Javascript
使用jQuery+HttpHandler+xml模拟一个三级联动的例子
2011/08/09 Javascript
jQuery使用技巧简单汇总
2013/04/18 Javascript
12行javascript代码绘制一个八卦图
2015/04/02 Javascript
javascript实现的闭包简单实例
2015/07/17 Javascript
JS实现新浪博客左侧的Blog管理菜单效果代码
2015/10/22 Javascript
如何在Angular2中使用jQuery及其插件的方法
2017/02/09 Javascript
写一个移动端惯性滑动&回弹Vue导航栏组件 ly-tab
2018/03/06 Javascript
对vue中methods互相调用的方法详解
2018/08/30 Javascript
详解使用webpack+electron+reactJs开发windows桌面应用
2019/02/01 Javascript
使用react context 实现vue插槽slot功能
2019/07/18 Javascript
js实现百度淘宝搜索功能
2020/02/17 Javascript
[06:16]DOTA2守卫传承者——职业选手谈心路历程
2015/02/26 DOTA
Python中的pass语句使用方法讲解
2015/05/14 Python
python实现SMTP邮件发送功能
2020/06/16 Python
Python中 Lambda表达式全面解析
2016/11/28 Python
python实现图书借阅系统
2019/02/20 Python
利用Python半自动化生成Nessus报告的方法
2019/03/19 Python
tensorflow 获取checkpoint中的变量列表实例
2020/02/11 Python
Python读取二进制文件代码方法解析
2020/06/22 Python
torchxrayvision包安装过程(附pytorch1.6cpu版安装)
2020/08/26 Python
网络艺术零售业的先驱者:artrepublic
2017/09/26 全球购物
限量版运动鞋和街头服饰:TheDrop
2020/09/06 全球购物
日语专业毕业生求职信
2013/12/04 职场文书
工作决心书范文
2014/03/11 职场文书
化工工艺设计求职信
2014/06/25 职场文书
施工单位安全责任书
2014/07/24 职场文书
授权委托书协议书
2014/10/16 职场文书
2014年个人工作总结模板
2014/12/15 职场文书
骨干教师考核评语
2014/12/31 职场文书