手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JavaScript的Function详细
JavaScript的Function详细
摘要:Function(Built-inObject)Function(內置對象)FunctionistheobjectfromwhichJava...

Function(Built-inObject)

Function(內置對象)

FunctionistheobjectfromwhichJavaScriptfunctionsarederived.Functionsarefirst-classdatatypesinJavaScript,sotheymaybeassignedtovariablesandpassedtofunctionsasyouwouldanyotherpieceofdata.Functionsare,ofcourse,referencetypes.

TheFunctionobjectprovidesbothstaticpropertieslikelengthandpropertiesthatconveyusefulinformationduringtheexecutionofthefunction,forexample,thearguments[]array.

Constructor

varinstanceName=newFunction([arg1[,arg2[,...]],]body);

Thebodyparameterisastringcontainingthetextthatmakesupthebodyofthefunction.TheoptionalargN'sarethenamesoftheformalparametersthefunctionaccepts.Forexample:

varmyAdd=newFunction("x","y","returnx+y");

varsum=myAdd(17,34);

Properties

arguments[]Animplicitlyfilledandimplicitlyavailable(directlyusableas"arguments"fromwithinthefunction)arrayofparametersthatwerepassedtothefunction.Thisvalueisnullifthefunctionisnotcurrentlyexecuting.(IE4+(JScript2.0+),MOZ,N3+(JavaScript1.1+),ECMAEdition1)

arguments.calleeReferencetothecurrentfunction.Thispropertyisdeprecated.(N4+,MOZ,IE5.5+)

arguments.callerReferencetothefunctionthatinvokedthecurrentfunction.Thispropertyisdeprecated.(N3,IE4+)

arguments.lengthThenumberofargumentsthatwerepassedtothefunction.(IE4+(JScript2.0+),MOZ,N3+(JavaScript1.1+),ECMAEdition1)

arityNumericvalueindicatinghowmanyargumentsthefunctionexpects.Thispropertyisdeprecated.(N4+,MOZ)

callerReferencetothefunctionthatinvokedthecurrentfunctionornullifcalledfromtheglobalcontext.(IE4+(JScript2.0+),MOZ,N3+)

constructorReferencetotheconstructorobjectthatcreatedtheobject.(IE4+(JScript2.0+),N3+(JavaScript1.1+),ECMAEdition1)

lengthThenumberofargumentsthefunctionexpectstobepassed.(IE4+(JScript2.0+),N3+(JavaScript1.1+),ECMAEdition1)

prototypeReferencetotheobject'sprototype.(IE4+(JScript2.0+),N3+(JavaScript1.1+),ECMAEdition1)

Methods

apply(thisArg[,argArray])InvokesthefunctionwiththeobjectreferencedbythisArgasitscontext(soreferencestothisinthefunctionreferencethisArg).TheoptionalparameterargArraycontainsthelistofparameterstopasstothefunctionasitisinvoked.(IE5.5+(JScript5.5+),N4.06+(JavaScript1.3+),MOZ,ECMAEdition3)

call(thisArg[,arg1[,arg2[,...]]])InvokesthefunctionwiththeobjectreferencedbythisArgasitscontext(soreferencestothisinthefunctionreferencethisArg).TheoptionalparametersargNarepassedtothefunctionasitisinvoked.(IE5.5+(JScript5.5+),N4.06+(JavaScript1.3+),MOZ,ECMAEdition3)

toString()Returnsthestringversionofthefunctionsource.Thebodyofbuilt-inandbrowserobjectswilltypicallyberepresentedbythevalue"[nativecode]".(IE4+(JScript2.0+),N3+(JavaScript1.1+),MOZ,ECMAEdition1)

valueOf()Returnsthestringversionofthefunctionsource.Thebodyofbuilt-inandbrowserobjectswilltypicallyberepresentedbythevalue"[nativecode]".(IE4+(JScript2.0+),N3+(JavaScript1.1+),MOZ,ECMAEdition1)

Support

SupportedinIE4+(JScript2.0+),N3+(JavaScript1.1+),MOZ,ECMAScriptEdition1.

Notes

Generalexamplesoffunctionsarefoundthroughoutthebook,butseeChapter5forexamplesoftheadvancedaspectsoffunctionsandtheFunctionobject.

【JavaScript的Function详细】相关文章:

JavaScript中的small()方法使用详解

详解 JavaScript 闭包的小知识

JavaScript容易犯错的九个陷阱

JavaScript中getUTCMinutes()方法的使用详解

在HTML中插入JavaScript代码的示例

JavaScript中的Math.LOG2E属性使用详解

Javascript中With语句用法实例

JavaScript的RequireJS库入门指南

编写高质量JavaScript代码的基本要点

JavaScript版代码高亮

精品推荐
分类导航