學習 DOJO入門 類定義

2021-09-09 04:00:42 字數 2169 閱讀 8361

一段dojo定義類的**:

dojo.declare(

"testclass",

null,

,staticvalue:,

constructor : function(id,name,age)

});var test=new testclass(1,"john","12");

console.log("****** argument id:" + test.id);

console.log("complex argument info:"+test.info.name+" "+test.info.age);

console.log("count:"+test.staticvalue.count);

var test2=new testclass();

console.log("count:"+test.staticvalue.count);

第乙個引數「testclass」為類名。

「null」,為指定的父類。

第三個引數是個hash,即是{}之間的部分。

id為乙個簡單引數

info則是乙個複雜引數

staticvalue則是乙個靜態變數,「staticvalue」是自定義的,只要在建構函式裡沒有傳參改變的變數,都是靜態變數,這是dojo特別之處。

constructor則是建構函式。

一段**:

dojo.declare(

"testclass",

null

, ,

staticvalue:,

constructor :

function

(id,name,age) ,printinfo:function

()}

);var test=new testclass(1,"john","12");

console.log(test.printinfo());

printinfo()方法就被定義了。

執行結果如下:

>>> dojo.declare( "testclass", null, ,

staticvalue:,

constructor :

function

(id,name,age) ,

printinfo:

function

(), printinfo:

function

(newname)

});var test=new testclass(1,"john","12");

console.log(test.printinfo());

console.log(test.printinfo("mike"));

執行結果則是:

>>> dojo.declare( "testclass", null, ,

staticvalue:,

constructor :

function

(id,name,age) ,

printinfo:

function

(), printinfo:

function

(newname)

return "姓名:"+this.info.name+" 年齡:"+this

.info.age;}}

);var test=new testclass(1,"john","12");

console.log(test.printinfo());

console.log(test.printinfo("mike"));

注意這幾行:

if(newname!=undefined)

由於是初學,暫只研究出這種方法,坦白說,略囧。

以上純屬誤解,undefined的出現,確實是和js的順序執行有關,但是更主要的原因在於,「過載」

dojo不支援方法的過載,但是過載的寫法並不會導致出錯,而是後定義的方法覆蓋先定義的方法。

於是,之前定義的兩個printinfo方法,其實只有第二個有效。

所以,當呼叫printinfo()的時候,引數newname就成undefined了。

dojo學習之旅 一 入門

始終使用web伺服器 內容參考 dojo start dojoconfig的配置 dojo從1.6版本引入amd,djconfig也變成了dojoconfig。dojoconfig是乙個頁面dojo配置的主要制所在,它會被模組載入器和全域性選項元件所引用。如果想進行dojo自定義程式設計,它還可以進...

指令碼入門 類的方法

unity培訓,unity資源,unity教學,等待您的加入,我們致力於研究unity3d 指令碼入門 類的方法 1.類的物件 類就是一類事物,而物件就是乙個事物,一類事物中包含若干的事物 而這其中的具體的事物就是物件 2.類的宣告 類成員可以包括 常數 字段 方法 屬性 事件 索引器 運算子 例項...

c 入門 型別轉化

無論是什麼型別,所有的資料都是一系列的位,即一系列0和1。變數的含義是通過解釋這些資料的方式來傳達的。型別轉換就是將資料用不同的方式來解發布來 1.隱式轉換 從型別a到型別b的轉換可以在所有情況下進行,執行轉換的規則非常簡單,可以讓編譯器執行轉換。隱式轉換不需要單獨的表示式,只需要把滿足隱式轉換條件...