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 16 Javascript
加载 Javascript 最佳实践
Oct 30 Javascript
ie支持function.bind()方法实现代码
Dec 27 Javascript
bootstrap3 兼容IE8浏览器!
May 02 Javascript
利用原生js和jQuery实现单选框的勾选和取消操作的方法
Sep 04 Javascript
JS区分Object与Aarry的六种方法总结
Feb 27 Javascript
vue基于Element构建自定义树的示例代码
Sep 19 Javascript
Vuejs学习笔记之使用指令v-model完成表单的数据双向绑定
Apr 29 Javascript
Layui实现数据表格默认全部显示(不要分页)
Oct 26 Javascript
js实现简易计算器小功能
Nov 18 Javascript
Vue和Flask通信的实现
May 19 Vue.js
JS创建或填充任意长度数组的小技巧汇总
Oct 24 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
骨王战斗力在公会成员中排不进前五,却当选了会长,原因竟是这样
2020/03/02 日漫
Yii实现MySQL多数据库和读写分离实例分析
2014/12/03 PHP
PHP模板引擎Smarty自定义变量调解器用法
2016/04/11 PHP
php简单创建zip压缩文件的方法
2016/04/30 PHP
PHP的RSA加密解密方法以及开发接口使用
2018/02/11 PHP
PHP安全之register_globals的on和off的区别
2020/07/23 PHP
PHP读取文件或采集时解决中文乱码
2021/03/09 PHP
用htc组件制作windows选项卡
2007/01/13 Javascript
Javascript 跨域访问解决方案
2009/02/14 Javascript
JavaScript中valueOf函数与toString方法深入理解
2012/12/02 Javascript
document.documentElement的一些使用技巧
2013/04/18 Javascript
wap手机图片滑动切换特效无css3元素js脚本编写
2014/07/28 Javascript
在JS数组特定索引处指定位置插入元素的技巧
2014/08/24 Javascript
Nodejs中调用系统命令、Shell脚本和Python脚本的方法和实例
2015/01/01 NodeJs
javascript html5实现表单验证
2016/03/01 Javascript
详解ECharts使用心得总结
2016/12/06 Javascript
原生js实现轮播图
2017/02/27 Javascript
jQuery插件FusionCharts实现的2D面积图效果示例【附demo源码下载】
2017/03/06 Javascript
jQuery插件HighCharts绘制2D柱状图、折线图和饼图的组合图效果示例【附demo源码下载】
2017/03/09 Javascript
AngularJS封装$http.post()实例详解
2017/05/06 Javascript
jQuery选择器之子元素选择器详解
2017/09/18 jQuery
jQuery实现的卷帘门滑入滑出效果【案例】
2019/02/18 jQuery
nodejs中实现修改用户路由功能
2019/05/24 NodeJs
python实现RabbitMQ的消息队列的示例代码
2018/11/08 Python
python3.7 sys模块的具体使用
2019/07/22 Python
python中seaborn包常用图形使用详解
2019/11/25 Python
django 中使用DateTime常用的时间查询方式
2019/12/03 Python
Django之腾讯云短信的实现
2020/06/12 Python
销售团队口号大全
2014/06/06 职场文书
创优争先心得体会
2014/09/11 职场文书
2015年七夕情人节感言
2015/08/03 职场文书
2016年大学生暑期社会实践方案
2015/11/26 职场文书
2016年万圣节活动总结
2016/04/05 职场文书
同学聚会开幕词
2019/04/02 职场文书
python四种出行路线规划的实现
2021/06/23 Python
MySQL和Oracle批量插入SQL的通用写法示例
2021/11/17 MySQL