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面向对象之静态与非静态类
Feb 03 Javascript
基于JQuery的cookie插件
Apr 07 Javascript
javascript中的继承实例代码
Apr 27 Javascript
JS获取农历日期具体实例
Nov 14 Javascript
js判断某个方法是否存在实例代码
Jan 10 Javascript
js实现刷新iframe的方法汇总
Apr 27 Javascript
jQuery选择器总结之常用元素查找方法
Aug 04 Javascript
jQuery滚动条美化插件nicescroll简单用法示例
Apr 18 jQuery
vue实现类似淘宝商品评价页面星级评价及上传多张图片功能
Oct 29 Javascript
VuePress 快速踩坑小结
Feb 14 Javascript
JS实现电脑虚拟键盘的操作
Jun 24 Javascript
vue使用v-model进行跨组件绑定的基本实现方法
Apr 28 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实现WEB动态网页静态
2006/10/09 PHP
php学习之变量的使用
2011/05/29 PHP
PHP网页游戏学习之Xnova(ogame)源码解读(十一)
2014/06/25 PHP
LNMP部署laravel以及xhprof安装使用教程
2017/09/14 PHP
Add a Table to a Word Document
2007/06/15 Javascript
JS中字符问题(二进制/十进制/十六进制及ASCII码之间的转换)
2008/11/03 Javascript
jQuery之网页换肤实现代码
2011/04/30 Javascript
一个JavaScript递归实现反转数组字符串的实例
2014/10/14 Javascript
javascript判断并获取注册表中可信任站点的方法
2015/06/01 Javascript
JS实现自动变换的菜单效果代码
2015/09/09 Javascript
JS中改变this指向的方法(call和apply、bind)
2016/03/26 Javascript
Knockoutjs 学习系列(二)花式捆绑
2016/06/07 Javascript
JavaScript中style.left与offsetLeft的使用及区别详解
2016/06/08 Javascript
canvas轨迹回放功能实现
2017/12/20 Javascript
使用vue的transition完成滑动过渡的示例代码
2018/06/25 Javascript
Vue中保存数据到磁盘文件的方法
2018/09/06 Javascript
微信小程序云开发(数据库)详解
2019/05/17 Javascript
jquery实现点击弹出对话框
2020/02/08 jQuery
[04:30]显微镜下的DOTA2第五期——拉比克
2013/09/26 DOTA
[02:03]DOTA2亚洲邀请赛 HGT战队出场宣传片
2015/02/07 DOTA
Python学习笔记之常用函数及说明
2014/05/23 Python
python实现的文件夹清理程序分享
2014/11/22 Python
Python 列表排序方法reverse、sort、sorted详解
2016/01/22 Python
Python实现可自定义大小的截屏功能
2018/01/20 Python
pandas dataframe添加表格框线输出的方法
2019/02/08 Python
使用python3调用wxpy模块监控linux日志并定时发送消息给群组或好友
2019/06/05 Python
Python将文字转成语音并读出来的实例详解
2019/07/15 Python
html5 canvas绘制网络字体的常用方法
2019/08/26 HTML / CSS
香港家用健身器材、运动器材及健康美容仪器专门店:FitBoxx
2019/12/05 全球购物
人力资源专业推荐信
2013/11/29 职场文书
青年教师培训方案
2014/02/06 职场文书
产品设计开发计划书
2014/05/07 职场文书
高二学年自我鉴定范文(2篇)
2014/09/26 职场文书
庆七一宣传标语
2014/10/08 职场文书
2014年电话销售工作总结
2014/12/01 职场文书
工商局个人工作总结
2015/03/03 职场文书