javascript arguments¶ÔÏó
ÔÚjavascriptº¯ÊýÌåÄÚ£¬±êʶ·ûarguments¾ßÓÐÌØÊ⺬Òå¡£ËüÊǵ÷ÓöÔÏóµÄÒ»¸öÌØÊâÊôÐÔ£¬ÓÃÀ´ÒýÓÃArguments¶ÔÏó¡£Arugments¶ÔÏó¾ÍÏñÊý×飬עÒâÕâÀïÖ»ÊÇÏñ²¢²»Êǹþ¡£
javascriptº¯ÊýÌåÄÚ£¬argumentsÏñÊý×é(²¢²»ÊÇÕæµÄÊý×飬ÊÇÒ»¸öArguments¶ÔÏó£¬ÔÙ´ÎÇ¿µ÷)Ò»Ñù£¬ÓÐlengthÊôÐÔ£¬¿ÉÒÔ´ú±í´«¸øº¯ÊýµÄ²ÎÊýµÄ¸öÊý¡£
ÒýÓÃÒ»¸öÐÎʽ²ÎÊý¿ÉÒÔÓòÎÊýÃû£¬Ò²¿ÉÒÔÓÃarguments[]Êý×éÐÎʽ£¬ÆäÖÐarguments[0]±íʾµÚÒ»¸ö²ÎÊý¡£
ËùÒÔ£¬javascriptÖÐArguments¶ÔÏóÊǺ¯ÊýµÄʵ¼Ê²ÎÊý£¬ÏÂÃ棬ÎÒÃÇÒ»ÆðÀ´½øÈëÕâÉñÆæµÄ¹ú¶È£¬Ò»¿ú¾¿¾¹¡£
arguments.lengthÊôÐÔ£º
js²»»áÖ÷¶¯ÎªÄãÅжÏÄãµ½µ×¸øº¯Êý´«Á˶àÉÙ¸ö²ÎÊý£¬Èç¹ûÄã¶à´«ÁË£¬¶àÓàµÄ²¿·Ö¾ÍûÓб»Ê¹Óã¬Èç¹ûÄãÉÙ´«ÁË£¬ÄÇôû´«µÄ²ÎÊýÖµ¾ÍÊÇundefined
ËùÒÔÎÒÃÇ¿ÉÒÔ½èÖúargumentsµÄlengthÊôÐÔÀ´¼ì²âµ÷Óú¯ÊýʱÊÇ·ñʹÓÃÁËÕýÈ·ÊýÄ¿µÄʵ¼Ê²ÎÊý£¬ÒòΪjavascriptÊDz»»áΪÄã×öÕâЩʵÄ
function f(x,y,z)
{
//Ê×Ïȼì²é´«µÝµÄ²ÎÊýÊýÁ¿ÊÇ·ñÕýÈ·
if(arguments.length != 3)
{
throw new Error("function f called with " + arguments.length + "arguments ,but it not 3 arguments.");
}
//ÏÂÃæÔËÐÐÕæÕýµÄº¯Êý
}
arguments»¹ÎªÎÒÃÇÌṩÁËÕâÑùÒ»ÖÖ¿ÉÄÜ£¬¾ÍÊÇΪһ¸öº¯Êý´«ÈÎÒâÊýÄ¿µÄʵ¼Ê²ÎÊý£º
±ÈÈç˵£¬ÎÒÏëÅжÏÄã´«¸øÎÒµÄһЩÊý×ֵĴóС£¬È¡³ö×î´óµÄÄǸö£¬¶Ô£¬Ã»´í£¬Äã´«¶àÉÙ²ÎÊý¶¼ÐУ¬µ«ÊÇÇ°ÌáÊÇÄãÒª´«Êý×Ö£¬ÒòΪÎÒÔÚº¯ÊýÄÚ²¿ÀÁµÃÅжÏÁË¡£ºÇ¡£
function max()
{
//¸ù¾ÝÎÒÉÏһƪÈÕÖ¾£¬ÕâÒѾÊÇJavaScriptÄÚ×îСµÄÊý×ÖÁË
var m = Number.NEGATIVE_INFINITY;
for(var i = 0; i < arguments.length; i++)
{
//Ö»ÒªÓÐÈκÎÒ»¸ö²ÎÊý±Èm´ó£¬ÄÇôm¾Í±ä³ÉÁËÕâ¸ö²ÎÊýµÄÖµ
if(arguments[i] > m)
m = arguments[i];
}
return m;
}
ÔõôÑù£¿Õâ¸ö·½·¨ºÜÇÉÃî°É£¿ºÇºÇ¡£
˵Ã÷Ò»ÏÂargumentsÓëÕæÕý´«µÄÐÎʽ²ÎÊýÊÇÒ»Öµģº
±ÈÈ磬Äã¸øº¯Êý´«ÁËÒ»¸ö½ÐparamµÄ²ÎÊý£¬²¢ÇÒÖ»ÓÐÕâÒ»¸ö²ÎÊý£¬ÄÇôpa
Ïà¹ØÎĵµ£º
¿´ÊéµÄʱºòÓöµ½ÕâÑùÒ»¸öÎÊÌ⣬³ÌÐò´úÂëÈçÏÂ
var ob = function(){
var obj = this;
function fn1(){
alert( obj === window );//false
alert( this === window );//ture
}
this.fn2 = function() {
fn1();
}
}
µ±Ê±ºÜ²»Ã÷°×fn1ÀïÃæµÚ¶þ¸öalertµÄ½á¹û£¬Îª ......
SCRIPT 񈬀
ÓÃÓÚ°üº¬JavaScript´úÂë.
ÊôÐÔ
LANGUAGE ¶¨Òå½Å±¾ÓïÑÔ
SRC ¶¨ÒåÒ»¸öURLÓÃÒÔÖ¸¶¨ÒÔ.JS½áβµÄÎļþ
window¶ÔÏó
ÿ¸öHTMLÎĵµµÄ¶¥²ã¶ÔÏó.
ÊôÐÔ
frames[] ×ÓèåÊý×é.ÿ¸ö×ÓèåÊý×é°´Ô´ÎĵµÖж¨ÒåµÄ ......
ȺÀïÌÖÂÛ¹ýµÄÌâÄ¿£¬·ÖÏíһϡ£
function test(){
var m=n=1;
alert(m);
}
alert(n);
//ÒòΪtestº¯ÊýûÓÐÖ´ÐУ¬³Ì¶È¿ØÖÆÁ÷²»ÄܽøÈë½øÐнâÎö£¬ÀïÃæµÄ¶«Î÷¶ÔÍâÃæ²»¿É¼û£¬Òò´Ë±¨´í
function test(){
var m=n=1;
alert(m);
}
test();
alert(n);
//µ±testÖ´Ðкó£¬Í ......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
&nb ......