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 相关文章推荐
HTML5附件拖拽上传drop & google.gears实现代码
Apr 28 Javascript
JavaScript实现标题栏文字轮播效果代码
Oct 24 Javascript
jQuery实现textarea自动增长宽高的方法
Dec 18 Javascript
JavaScript提高网站性能优化的建议(二)
Jul 24 Javascript
JavaScript 输出显示内容(document.write、alert、innerHTML、console.log)
Dec 14 Javascript
jquery pagination分页插件使用详解(后台struts2)
Jan 22 Javascript
ES6学习笔记之正则表达式和字符串正则方法分析
Apr 25 Javascript
分析javascript中9 个常见错误阻碍你进步
Sep 18 Javascript
结合Vue控制字符和字节的显示个数的示例
May 17 Javascript
小程序实现左滑删除功能
Oct 30 Javascript
小程序实现图片预览裁剪插件
Nov 22 Javascript
Vue中this.$nextTick的作用及用法
Feb 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
asp和php下textarea提交大量数据发生丢失的解决方法
2008/01/20 PHP
重新认识php array_merge函数
2014/08/31 PHP
PHP多维数组转一维数组的简单实现方法
2015/12/23 PHP
阿里对象存储OSS在laravel框架中的使用方法
2019/10/13 PHP
laravel 框架执行流程与原理简单分析
2020/02/01 PHP
arguments对象
2006/11/20 Javascript
Save a File Using a File Save Dialog Box
2007/06/18 Javascript
用JS实现一个TreeMenu效果分享
2011/08/28 Javascript
Extjs 3.3切换tab隐藏相应工具栏出现空白解决
2013/04/02 Javascript
js倒计时小程序
2013/11/05 Javascript
javaScript 页面自动加载事件详解
2014/02/10 Javascript
javascript文件中引用依赖的js文件的方法
2014/03/17 Javascript
javascript中基本类型和引用类型的区别分析
2015/05/12 Javascript
JS实现带有抽屉效果的产品类网站多级导航菜单代码
2015/09/15 Javascript
jQuery实现的仿百度分页足迹效果代码
2015/10/30 Javascript
javascript实现下拉提示选择框
2015/12/29 Javascript
微信小程序实现的日期午别医生排班表功能示例
2019/01/09 Javascript
详解JS判断页面是在手机端还是在PC端打开的方法
2019/04/26 Javascript
vue中重定向redirect:‘/index‘,不显示问题、跳转出错的完美解决
2020/09/28 Javascript
Python中join和split用法实例
2015/04/14 Python
numpy实现合并多维矩阵、list的扩展方法
2018/05/08 Python
python实现关闭第三方窗口的方法
2019/06/28 Python
Python Subprocess模块原理及实例
2019/08/26 Python
Python自动化xpath实现自动抢票抢货
2020/09/19 Python
Python爬取股票信息,并可视化数据的示例
2020/09/26 Python
美国真皮手袋品牌:GiGi New York
2017/03/10 全球购物
什么是属性访问器
2015/10/26 面试题
爱祖国演讲稿
2014/05/04 职场文书
物流专业自荐信
2014/05/23 职场文书
国庆65周年演讲稿:回首往昔,展望未来
2014/09/21 职场文书
个人四风问题整改措施思想汇报
2014/10/04 职场文书
北京故宫导游词
2015/01/31 职场文书
材料员岗位职责
2015/02/10 职场文书
呼兰河传读书笔记
2015/06/30 职场文书
导游词之西递宏村
2019/12/10 职场文书
【DOTA2】半决赛强强对话~ PSG LGD vs EHOME - DPC 2022 CN REGIONAL FINALS WINTER
2022/04/02 DOTA