⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.html

📁 javascript 1.5规范
💻 HTML
📖 第 1 页 / 共 5 页
字号:
</FONT><P><A NAME="1237568"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><B>Example 2.</B> This example defines a function that creates HTML lists. The only formal argument for the function is a string that is <FONT FACE="courier, couriernew, monospaced size">"U"</FONT> if the list is to be unordered (bulleted), or <FONT FACE="courier, couriernew, monospaced size">"O"</FONT> if the list is to be ordered (numbered). The function is defined as follows:</zparagraph></FONT><P><A NAME="1237569"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>function list(type) {<br>&nbsp;&nbsp;&nbsp;document.write("&lt;" + type + "L&gt;") // begin list<br>&nbsp;&nbsp;&nbsp;// iterate through arguments<br>&nbsp;&nbsp;&nbsp;for (var i=1; i&lt;arguments.length; i++) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.write("&lt;LI&gt;" + arguments[i])<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;document.write("&lt;/" + type + "L&gt;") // end list<br>}</zcodeline></FONT><P><A NAME="1237570"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>You can pass any number of arguments to this function, and it displays each argument as an item in the type of list indicated. For example, the following call to the function</zparagraph></FONT><P><A NAME="1237571"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>list("U", "One", "Two", "Three")</zcodeline></FONT><P><A NAME="1237572"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>results in this output:</zparagraph></FONT><P><A NAME="1237573"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>&lt;UL&gt;<br>&lt;LI&gt;One<br>&lt;LI&gt;Two<br>&lt;LI&gt;Three<br>&lt;/UL&gt;</zcodeline></FONT><P><A NAME="1237577"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In server-side JavaScript, you can display the same output by calling the <A HREF="../toplev.html#15484"  ><FONT FACE="courier, couriernew, monospaced size">write</FONT></A> function instead of using <FONT FACE="courier, couriernew, monospaced size">document.write</FONT>.</zparagraph></FONT><P><BR><P><A NAME="1196419"> </A><A NAME="arguments.callee"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4"><B><zrefhead2>arguments.callee</zrefhead2></B></FONT><P><A NAME="1196433"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Specifies the function body of the currently executing function.<BR><P><TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT><BR><BR>  <TR>    <TD VALIGN=TOP><P><A NAME="1230356"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><I>Property of</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1230361"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><A HREF="function.html#1193312"  >arguments</A> local variable; <A HREF="function.html#1193137"  >Function</A> (deprecated)</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1196429"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><I>Implemented in</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1196431"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>JavaScript 1.2</ztabletext></FONT><P><A NAME="1216461"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext></ztabletext></FONT><P><A NAME="1196432"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>JavaScript 1.4: Deprecated <FONT FACE="courier, couriernew, monospaced size">callee</FONT> as a property of <FONT FACE="courier, couriernew, monospaced size">Function.arguments</FONT>, retained it as a property of a function's local <FONT FACE="courier, couriernew, monospaced size">arguments</FONT> variable.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1196953"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><I>ECMA version</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1196955"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>ECMA-262</ztabletext></FONT>&nbsp;</TD>  </TR></TABLE><P></zparagraph></FONT><P><BR><A NAME="1196434"> </A><A NAME="Description"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Description</zrefheader></B></FONT><BR><A NAME="1230831"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><FONT FACE="courier, couriernew, monospaced size">arguments.callee</FONT> is a property of the <A HREF="function.html#1193312"  >arguments</A> local variable available within all function objects; <FONT FACE="courier, couriernew, monospaced size">arguments.callee</FONT> as a property of <FONT FACE="courier, couriernew, monospaced size">Function</FONT> is no longer used.</zparagraph></FONT><P><A NAME="1196435"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The <FONT FACE="courier, couriernew, monospaced size">callee</FONT> property is available only within the body of a function.</zparagraph></FONT><P><A NAME="1196436"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The <FONT FACE="courier, couriernew, monospaced size">this</FONT> keyword does not refer to the currently executing function. Use the <FONT FACE="courier, couriernew, monospaced size">callee</FONT> property to refer to a function within the function body.</zparagraph></FONT><P><BR><A NAME="1196437"> </A><A NAME="Examples"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Examples</zrefheader></B></FONT><BR><A NAME="1196438"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The following function returns the value of the function's <FONT FACE="courier, couriernew, monospaced size">callee</FONT> property.</zparagraph></FONT><P><A NAME="1227944"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>function myFunc() {<br>&nbsp;&nbsp;&nbsp;return arguments.callee<br>}</zcodeline></FONT><P><A NAME="1218821"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The following value is returned:</zparagraph></FONT><P><A NAME="1218822"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>function myFunc() { return arguments.callee; }</zcodeline></FONT><P><BR><A NAME="1196440"> </A><A NAME="See also"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>See also</zrefheader></B></FONT><BR><A NAME="1196444"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><A HREF="function.html#1193312"  >Function.arguments</A></zparagraph></FONT><P><BR><P><A NAME="1196447"> </A><A NAME="arguments.caller"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4"><B><zrefhead2>arguments.caller</zrefhead2></B></FONT><P><A NAME="1196462"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Specifies the name of the function that invoked the currently executing function.<BR><P><TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT><BR><BR>  <TR>    <TD VALIGN=TOP><P><A NAME="1196450"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><I>Property of</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1196455"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><A HREF="function.html#1193137"  >Function</A></ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1196457"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><I>Implemented in</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1196459"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>JavaScript 1.1, NES 2.0</ztabletext></FONT><P><A NAME="1196460"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext></ztabletext></FONT><P><A NAME="1196461"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Deprecated in JavaScript 1.3</ztabletext></FONT>&nbsp;</TD>  </TR></TABLE><P></zparagraph></FONT><P><BR><A NAME="1196463"> </A><A NAME="Description"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Description</zrefheader></B></FONT><BR><A NAME="1196467"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><FONT FACE="courier, couriernew, monospaced size">caller</FONT> is no longer used.</zparagraph></FONT><P><A NAME="1196468"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The <FONT FACE="courier, couriernew, monospaced size">caller</FONT> property is available only within the body of a function.</zparagraph></FONT><P><A NAME="1196469"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>If the currently executing function was invoked by the top level of a JavaScript program, the value of <FONT FACE="courier, couriernew, monospaced size">caller</FONT> is null.</zparagraph></FONT><P><A NAME="1196470"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The <FONT FACE="courier, couriernew, monospaced size">this</FONT> keyword does not refer to the currently executing function, so you must refer to functions and <FONT FACE="courier, couriernew, monospaced size">Function</FONT> objects by name, even within the function body.</zparagraph></FONT><P><A NAME="1196471"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The <FONT FACE="courier, couriernew, monospaced size">caller</FONT> property is a reference to the calling function, so</zparagraph></FONT><P><ul><A NAME="1196472"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B>  <li></B><zsmartlist1>If you use it in a string context, you get the result of calling <FONT FACE="courier, couriernew, monospaced size">functionName.toString</FONT>. That is, the decompiled canonical source form of the function.</zsmartlist1></FONT><P><A NAME="1196473"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B>  <li></B><zsmartlist1>You can also call the calling function, if you know what arguments it might want. Thus, a called function can call its caller without knowing the name of the particular caller, provided it knows that all of its callers have the same form and fit, and that they will not call the called function again unconditionally (which would result in infinite recursion).</zsmartlist1></FONT><P></ul><BR><A NAME="1196474"> </A><A NAME="Examples"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Examples</zrefheader></B></FONT><BR><A NAME="1196475"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The following code checks the value of a function's <FONT FACE="courier, couriernew, monospaced size">caller</FONT> property.</zparagraph></FONT><P><A NAME="1196476"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>function myFunc() {<br>&nbsp;&nbsp;&nbsp;if (arguments.caller == null) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ("The function was called from the top!")<br>&nbsp;&nbsp;&nbsp;} else return ("This function's caller was " + arguments.caller)<br>}</zcodeline></FONT><P><BR><A NAME="1196477"> </A><A NAME="See also"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>See also</zrefheader></B></FONT><BR><A NAME="1196481"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><A HREF="function.html#1193312"  >Function.arguments</A></zparagraph></FONT><P><BR><P><A NAME="1196484"> </A><A NAME="arguments.length"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4"><B><zrefhead2>arguments.length</zrefhead2></B></FONT><P><A NAME="1196497"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Specifies the number of arguments passed to the function.<BR><P><TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">  <CAPTION></CAPTION><P><FONT FACE=""

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -