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获取选中的文本的方法代码
Oct 30 Javascript
jQuery实现的一个自定义Placeholder属性插件
Aug 11 Javascript
js获取时间并实现字符串和时间戳之间的转换
Jan 05 Javascript
Javascript控制div属性动态变化实例分析
Oct 08 Javascript
jQuery实现form表单基于ajax无刷新提交方法详解
Dec 08 Javascript
微信小程序实现实时圆形进度条的方法示例
Feb 24 Javascript
jQuery倒计时代码(超简单)
Feb 27 Javascript
HTML5+JS+JQuery+ECharts实现异步加载问题
Dec 16 jQuery
JS实现键值对遍历json数组功能示例
May 30 Javascript
vue自动化路由的实现代码
Sep 30 Javascript
Vue混入mixins滚动触底的方法
Nov 22 Javascript
vue实现的多页面项目如何优化打包的步骤详解
Jul 19 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图片处理类(水印、透明度、旋转)
2015/10/21 PHP
PHP验证码生成原理和实现
2016/01/24 PHP
Thinkphp3.2.3整合phpqrcode生成带logo的二维码
2016/07/21 PHP
php实现头像上传预览功能
2017/04/27 PHP
laravel 实现划分admin和home 模块分组
2019/10/15 PHP
Laravel5.1框架路由分组用法实例分析
2020/01/04 PHP
tp5.1 框架数据库常见操作详解【添加、删除、更新、查询】
2020/05/26 PHP
js同比例缩放图片的小例子
2013/10/30 Javascript
JS+CSS 制作的超级简单的下拉菜单附图
2013/11/22 Javascript
Javascript编写2048小游戏
2015/07/07 Javascript
最简单的JavaScript图片轮播代码(两种方法)
2015/12/18 Javascript
学习JavaScript鼠标响应事件
2015/12/25 Javascript
JavaScript操作select元素和option的实例代码
2016/01/29 Javascript
javascript的列表切换【实现代码】
2016/05/03 Javascript
jQuery插件FusionCharts实现的MSBar2D图效果示例【附demo源码】
2017/03/24 jQuery
docker中编译nodejs并使用nginx启动
2017/06/23 NodeJs
浅谈vue-lazyload实现的详细过程
2017/08/22 Javascript
vue使用axios跨域请求数据问题详解
2017/10/18 Javascript
webpack自动打包和热更新的实现方法
2019/06/24 Javascript
win10系统中安装scrapy-1.1
2016/07/03 Python
python3 pandas 读取MySQL数据和插入的实例
2018/04/20 Python
python实现学生管理系统开发
2020/07/24 Python
抽象类和接口的区别
2012/09/19 面试题
EJB面试题
2015/07/28 面试题
应届大专毕业生个人自荐信
2013/09/22 职场文书
平面设计自荐信
2013/10/07 职场文书
女大学生自我鉴定
2013/12/09 职场文书
授权委托书公证
2014/09/14 职场文书
酒店餐厅2014重阳节活动策划方案
2014/09/16 职场文书
党员国庆节演讲稿范文2014
2014/09/21 职场文书
2015年学校精神文明工作总结
2015/05/27 职场文书
毛主席纪念堂观后感
2015/06/17 职场文书
入伍志愿书怎么写?
2019/07/19 职场文书
详解Python+OpenCV进行基础的图像操作
2022/02/15 Python
SQL Server查询某个字段在哪些表中存在
2022/03/03 SQL Server
CSS使用Flex和Grid布局实现3D骰子
2022/08/05 HTML / CSS