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 相关文章推荐
web前端开发也需要日志
Dec 09 Javascript
使用Java实现简单的server/client回显功能的方法介绍
May 03 Javascript
得到form下的所有的input的js代码
Nov 07 Javascript
jQuery获得IE版本不准确webbrowser的解决方法
Feb 23 Javascript
js判断页面中是否有指定控件的简单实例
Mar 04 Javascript
JS/jQuery判断DOM节点是否存在的简单方法
Nov 24 Javascript
解析如何利用iframe标签以及js制作时钟
Dec 08 Javascript
微信小程序图片横向左右滑动案例
May 19 Javascript
Vue瀑布流插件的使用示例
Sep 19 Javascript
在layui.use 中自定义 function 的正确方法
Sep 16 Javascript
ElementUI多个子组件表单的校验管理实现
Nov 07 Javascript
JS实现字体背景跑马灯
Jan 06 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中的时间显示
2007/01/18 PHP
php中global和$GLOBALS[]的分析之一
2012/02/02 PHP
PHP实现支持GET,POST,Multipart/form-data的HTTP请求类
2014/09/24 PHP
浅谈PHP中的Trait使用方法
2019/03/22 PHP
理解Javascript_11_constructor实现原理
2010/10/18 Javascript
Jquery跨域获得Json时invalid label错误的解决办法
2011/01/11 Javascript
24款热门实用的jQuery插件推荐
2014/12/24 Javascript
JavaScript通过Date-Mask将日期转换成字符串的方法
2015/06/04 Javascript
值得分享和收藏的Bootstrap学习教程
2016/05/12 Javascript
深入理解Node.js的HTTP模块
2016/10/12 Javascript
bootstrap实现每隔5秒自动轮播效果
2016/12/20 Javascript
SeaJS中use函数用法实例分析
2017/10/10 Javascript
浅谈PDF.js使用心得
2018/06/07 Javascript
解决vue props 拿不到值的问题
2018/09/11 Javascript
手把手带你封装一个vue component第三方库
2019/02/14 Javascript
9102年webpack4搭建vue项目的方法步骤
2019/02/20 Javascript
[01:34]2016国际邀请赛中国区预选赛IG战队教练采访
2016/06/27 DOTA
python 数据清洗之数据合并、转换、过滤、排序
2017/02/12 Python
Python函数参数操作详解
2018/08/03 Python
Python自动化运维之Ansible定义主机与组规则操作详解
2019/06/13 Python
10分钟用python搭建一个超好用的CMDB系统
2019/07/17 Python
python 非线性规划方式(scipy.optimize.minimize)
2020/02/11 Python
vue学习笔记之动态组件和v-once指令简单示例
2020/02/29 Python
Pycharm激活方法及详细教程(详细且实用)
2020/05/12 Python
Python参数传递及收集机制原理解析
2020/06/05 Python
python学习之使用Matplotlib画实时的动态折线图的示例代码
2021/02/25 Python
香港太阳眼镜网上商店:SmartBuyGlasses香港
2016/07/22 全球购物
享誉全球的多元化时尚精品购物平台:Farfetch发发奇(支持中文)
2017/08/08 全球购物
蒙蒂塞罗商店:Monticello Shop
2018/11/25 全球购物
俄罗斯汽车零件和配件在线商店:CarvilleShop
2019/11/29 全球购物
介绍下Java中==和equals的区别
2013/09/01 面试题
Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别?
2014/07/27 面试题
简易离婚协议书(范本)
2014/10/25 职场文书
义卖募捐活动总结
2015/05/09 职场文书
运动会宣传稿50字
2015/07/23 职场文书
linux下安装redis图文详细步骤
2021/12/04 Redis