JavaScript的Function详细_Javascript教程-查字典教程网
JavaScript的Function详细
JavaScript的Function详细
发布时间:2016-12-30 来源:查字典编辑
摘要: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教程学习
    热门Javascript教程学习
    编程开发子分类