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 相关文章推荐
一个加载js文件的小脚本
Jun 28 Javascript
jQuery 获取对象 定位子对象
May 31 Javascript
jQuery(1.6.3) 中css方法对浮动的实现缺陷分析
Sep 09 Javascript
ASP.NET jQuery 实例5 (显示CheckBoxList成员选中的内容)
Jan 13 Javascript
js的匿名函数使用介绍
Dec 11 Javascript
JavaScript判断变量是对象还是数组的方法
Aug 28 Javascript
全面解析DOM操作和jQuery实现选项移动操作代码分享
Jun 07 Javascript
AngularJS的ng Http Request与response格式转换方法
Nov 07 Javascript
JS异步加载的三种实现方式
Mar 16 Javascript
ES6新特性四:变量的解构赋值实例
Apr 21 Javascript
javascript input输入框模糊提示功能的实现
Sep 25 Javascript
用ES6写全屏滚动插件的示例代码
May 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
雄兵连三大错觉:凯莎没了,凉冰阵亡了,华烨觉得自己又行了
2020/04/09 国漫
PHP输出时间差函数代码
2013/01/28 PHP
Javascript与PHP验证用户输入URL地址是否正确
2014/10/09 PHP
浅谈PHP中Stream(流)
2015/06/08 PHP
PHP解析url并得到url参数方法总结
2018/10/11 PHP
jQuery实现Div拖动+键盘控制综合效果的方法
2015/03/10 Javascript
ECMAScript6中Set/WeakSet详解
2015/06/12 Javascript
jQuery实现鼠标点击弹出渐变层的方法
2015/07/09 Javascript
超漂亮的jQuery图片轮播特效
2015/11/24 Javascript
javascript数组对象常用api函数小结(连接,插入,删除,反转,排序等)
2016/09/20 Javascript
给easyui datebox扩展一个清空的实例
2016/11/09 Javascript
javascript判断回文数详解及实现代码
2017/02/03 Javascript
javascript 实现文本使用省略号替代(超出固定高度的情况)
2017/02/21 Javascript
JS如何判断浏览器类型和详细区分IE各版本浏览器
2017/03/04 Javascript
jQuery中each循环的跳出和结束实例
2017/08/16 jQuery
详解基于Vue,Nginx的前后端不分离部署教程
2018/12/04 Javascript
JavaScript实现星级评价效果
2019/05/17 Javascript
记录微信小程序 height: calc(xx - xx);无效问题
2019/12/30 Javascript
vue-cli点击实现全屏功能
2020/03/07 Javascript
vue实现购物车结算功能
2020/06/18 Javascript
如何配置vue.config.js 处理static文件夹下的静态文件
2020/06/19 Javascript
在vue中实现禁止屏幕滚动,禁止屏幕滑动
2020/07/22 Javascript
JS实现鼠标按下拖拽效果
2020/07/23 Javascript
vue实现登录、注册、退出、跳转等功能
2020/12/23 Vue.js
原生js实现滑块区间组件
2021/01/20 Javascript
Python多线程中阻塞(join)与锁(Lock)使用误区解析
2018/04/27 Python
django js实现部分页面刷新的示例代码
2018/05/28 Python
python数据预处理 :数据抽样解析
2020/02/24 Python
Pytorch环境搭建与基本语法
2020/06/03 Python
Python QTimer实现多线程及QSS应用过程解析
2020/07/11 Python
详解HTML5 canvas绘图基本使用方法
2018/01/29 HTML / CSS
后勤采购员岗位职责
2013/12/19 职场文书
商场活动策划方案
2014/01/24 职场文书
2014年协会工作总结
2014/11/22 职场文书
2014年前台文员工作总结
2014/12/08 职场文书
《这片土地是神圣的》教学反思
2016/02/16 职场文书