1.function 實際是一個內部對象,有兩種定義形式
一、function func1()
{ .....}
二、var myfun=function(){....}
2.this 與java中this一樣,都指向調用當前函數的對象
3.為class添加屬性和方法的方式:
一、function class1()
{
var s="abc";
this.p1=s;
this.method1=function(){
alert("method");
}
}
var obj1=new class1();通過new class1()獲得對象obj1,obj1便自動獲得了屬性p1 和方法method1
二、使用prototype對象
function class1()
{
this.prop=1;
}
class1.prototype.showProp=function()
{
alert(this.prop);
}
var obj1=new class1();
obj1.showProp();
4.函數對象還有一個屬性length,它表示函數定義時所指定的參數的個數,而非調用時實際傳遞的參數個數
function sum(a,b){
return a+b;
}
alert(sum.length); 輸出為2
posted on 2008-07-20 15:00
長春語林科技 閱讀(474)
評論(0) 編輯 收藏 所屬分類:
js