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 相关文章推荐
创建公共调用 jQuery Ajax 带返回值
Aug 01 Javascript
express的中间件bodyParser详解
Dec 04 Javascript
jQuery实现简单隔行变色的方法
Feb 20 Javascript
js基于cookie记录来宾姓名的方法
Jul 19 Javascript
javascript使用 concat 方法对数组进行合并的方法
Sep 08 Javascript
学习JavaScript图片预加载模块
Nov 07 Javascript
JS实现图片垂直居中显示小结
Dec 13 Javascript
JS常见创建类的方法小结【工厂方式,构造器方式,原型方式,联合方式等】
Apr 01 Javascript
jQuery Masonry瀑布流布局神器使用详解
May 25 jQuery
JavaScript设计模式之原型模式分析【ES5与ES6】
Jul 26 Javascript
vue加载完成后的回调函数方法
Sep 07 Javascript
JS事件绑定的常用方式实例总结
Mar 02 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 parse_url 一个好用的函数
2009/10/03 PHP
php实现aes加密类分享
2014/02/16 PHP
jQuery+PHP实现图片上传并提交功能
2020/07/27 PHP
js实现的网站首页随机公告随机公告
2007/03/14 Javascript
jQuery获取css z-index在各种浏览器中的返回值
2010/09/15 Javascript
利用Jquery实现可多选的下拉框
2014/02/21 Javascript
IE6-IE9中tbody的innerHTML不能赋值的解决方法
2014/06/05 Javascript
jQuery 实现侧边浮动导航菜单效果
2014/12/26 Javascript
javascript原始值和对象引用实例分析
2015/04/25 Javascript
jQuery查找节点并获取节点属性的方法
2016/09/09 Javascript
简单的js计算器实现
2016/10/26 Javascript
jQuery弹出层插件popShow用法示例
2017/01/23 Javascript
基于JavaScript实现购物车功能
2017/02/07 Javascript
js学习心得_一个简单的动画库封装tween.js
2017/07/14 Javascript
js实现input密码框显示/隐藏功能
2020/09/10 Javascript
基于Element的组件改造的树形选择器(树形下拉框)
2020/02/27 Javascript
[17:36]VG战队纪录片
2014/08/21 DOTA
理解Python中的类与实例
2015/04/27 Python
Python 实现淘宝秒杀的示例代码
2018/01/02 Python
python去掉空白行的多种实现代码
2018/03/19 Python
详解Python学习之安装pandas
2019/04/16 Python
Python实现的插入排序,冒泡排序,快速排序,选择排序算法示例
2019/05/04 Python
python基于opencv 实现图像时钟
2021/01/04 Python
html5指南-6.如何创建离线web应用程序实现离线访问
2013/01/07 HTML / CSS
HTML5+CSS3实现拖放(Drag and Drop)示例
2014/07/07 HTML / CSS
用Python写一个for循环的例子
2016/07/19 面试题
大一自我鉴定范文
2013/12/27 职场文书
元旦晚会上单位领导演讲稿
2014/01/05 职场文书
高二美术教学反思
2014/01/14 职场文书
《夕阳真美》教学反思
2014/04/27 职场文书
我的老师教学反思
2014/05/01 职场文书
2014财产信托协议书范本
2014/11/18 职场文书
归元寺导游词
2015/02/06 职场文书
爱国主义教育基地观后感
2015/06/18 职场文书
高一地理教学工作总结
2015/08/12 职场文书
解决flex布局中子项目尺寸不受flex-shrink限制
2022/05/11 HTML / CSS