|
復(fù)制代碼 代碼如下:
var f = function(x)
{
return x*x;
}
var f = function fact(x)
{
if(x<=1) return 1;
else return x*fact(x-1);
};
函數(shù)的參數(shù)數(shù)組:Arguments對(duì)象。常用arguments[i]引用,arguments.length等。
對(duì)象:
對(duì)象定義(函數(shù))中的方法,其實(shí)也是個(gè)函數(shù),與嵌套函數(shù)不同點(diǎn)在于:通過關(guān)鍵字this引用對(duì)象實(shí)體。
復(fù)制代碼 代碼如下:
function Rectangle(w, h)
{
this.width = w;
this.height = h;
this.area = area;
this.enlarge = Rectangle_enlarge;
this.setSize = setSize;
//通過構(gòu)造函數(shù)定義方法
function Rectangle_enlarge()
{
this.width *= 2;
this.height *= 2;
}
function setSize(width, height)
{
if(arguments.length < 2)
{
throw new Error("arguments less!");
}
else if(arguments.length >= 2)
{
this.width = width;
this.height = height;
}
}
function area()
{
return (this.width * this.height);
}
function area1()
{
alert(10);
}
}
原型對(duì)象和繼承:
原型對(duì)象是存放方法和其他常理屬性的理想場(chǎng)所,相當(dāng)于C#中的靜態(tài)字段。
JavaScript技術(shù):JavaScript函數(shù)、方法、對(duì)象代碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。