JavaScript的Function詳細(xì)
更新時(shí)間:2006年11月14日 00:00:00 作者:
Function (Built-in Object)
Function (內(nèi)置對(duì)象)
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.
Function (內(nèi)置對(duì)象)
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.
您可能感興趣的文章:
- eval(function(p,a,c,k,e,d)系列解密javascript程序
- javascript Object與Function使用
- Javascript 使用function定義構(gòu)造函數(shù)
- javascript 正則替換 replace(regExp, function)用法
- JavaScript 匿名函數(shù)(anonymous function)與閉包(closure)
- javascript兩種function的定義介紹及區(qū)別說明
- javascript學(xué)習(xí)筆記(四)function函數(shù)部分
- JavaScript Function函數(shù)類型介紹
- javascript中Function類型詳解
相關(guān)文章
javascript判斷回文數(shù)詳解及實(shí)現(xiàn)代碼
這篇文章主要介紹了javascript判斷回文數(shù)詳解及實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-02-02淺析函數(shù)聲明和函數(shù)表達(dá)式——函數(shù)聲明的聲明提前
下面小編就為大家?guī)硪黄獪\析函數(shù)聲明和函數(shù)表達(dá)式——函數(shù)聲明的聲明提前。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。2016-05-05javascript 進(jìn)階篇2 CSS XML學(xué)習(xí)
CSS我覺得應(yīng)該沒有不會(huì)的吧。。不過因?yàn)槲易约翰淮髸?huì)于是還是補(bǔ)在這里好了2012-03-03js中的setInterval和setTimeout使用實(shí)例
這篇文章主要介紹了javascript中的兩個(gè)定時(shí)執(zhí)行函數(shù)setInterval和setTimeout的用法,需要的朋友可以參考下2014-05-05Javascript基礎(chǔ)教程之break和continue語句
文章通過示例向我們展示了javascript中的break和continue語句,兩個(gè)對(duì)比起來,非常明了,需要的朋友可以參考下2015-01-01javascript中數(shù)組的多種定義方法和常用函數(shù)簡(jiǎn)介
本文簡(jiǎn)單介紹了javascript一維數(shù)組和二維數(shù)組的定義方法集錦以及常用函數(shù)簡(jiǎn)介。2014-05-05