锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
濡傛灉浣犳兂鍦╩yeclipse鐩綍涓嬪氨鍚姩瀹冿紝閭d箞鍔犱竴涓猙at鏂囦歡錛屽唴瀹癸細
start eclipse/eclipse.exe -vm jre/bin/javaw.exe
]]>
Dojo浣滀負涓涓己澶х殑javascript宸ュ叿綆憋紝鏈夊畠鑷繁闈㈠悜瀵硅薄鐨勫紑鍙戞柟寮忥紝鐢╠eclare瑙e喅浜嗗璞$殑鍒涘緩鍜岀戶鎵跨殑闂錛屾枃妗d腑鐨勪緥瀛愶細
dojo.declare("my.classes.bar", my.classes.foo, {
// properties to be added to the class prototype
someValue: 2,
// initialization function
constructor: function(){
this.myComplicatedObject = new ReallyComplicatedObject();
},
// other functions
someMethod: function(){
doStuff();
}
}
);
declare鐨勭涓涓弬鏁版槸瀵硅薄鍚嶇О錛屾渶鍚庝竴涓弬鏁版寚瀹氬湪榪欎釜瀵硅薄閲岃娣誨姞鐨勫唴瀹癸紝鍖呮嫭鍑芥暟鍜屽睘鎬э紝鍐欎釜渚嬪瓙
dojo.declare("Apple", null, {
price: 5,
constructor: function(weight) {
this.total = weight * this.price;
},
print: function() {
alert("The total price is " + this.total);
}
}
);
var myapple = new Apple(10);
myapple.print(); //杈撳嚭緇撴灉錛?The total price is 50"
涓婁緥閫氳繃declare鍒涘緩浜嗕竴涓狝pple瀵硅薄錛宩avascript鏈韓娌℃湁綾葷殑姒傚康錛屽彲浠ヤ嬌鐢ㄥ璞℃湰韜潵鍒涘緩鏂扮殑瀵硅薄myapple錛岄氳繃鏋勯犲嚱鏁扮殑鍙傛暟鍊艱綆楄嫻鏋滅殑鎬諱環(huán)錛宲rint鍑芥暟杈撳嚭緇撴灉錛岄潪甯稿艦璞$殑鏋勫緩浜嗕竴涓狝pple“綾?#8221;錛岄潪甯稿鏄撶悊瑙c傝娉ㄦ剰鐨勬槸錛岃繖閲屽鏋滃0鏄庨粯璁ゆ瀯閫犲嚱鏁幫紝 "new Apple(10)"灝嗙洿鎺ユ墽琛岄粯璁ゆ瀯閫犲嚱鏁幫紝甯﹀弬鏁扮殑鏋勯犲嚱鏁板氨琚拷鐣ヤ簡錛屽茍闈濩++涓『搴忔墽琛屻?
娉ㄦ剰dojo.declare絎簩涓弬鏁幫紝濡傛灉鍒涘緩涓涓嫭绔嬬殑鏂板璞★紝鍙互璁句負null錛屽綋闇瑕佷粠鍏朵粬涓涓垨澶氫釜瀵硅薄緇ф壙鏃訛紝鍒欎負瀵硅薄鍚嶇О錛岃繖鏍峰氨鏂逛究鐨勫疄鐜頒簡瀵硅薄緇ф壙銆傚涓璞$戶鎵匡紝declare絎簩涓弬鏁頒負涓鏁扮粍錛岀涓涓厓绱犱負鍘熷瀷鐖跺璞★紝鍏朵粬鐨勪負mixin瀵硅薄錛岄氳繃浠g爜鏉ョ悊瑙c?
<script>
dojo.declare("Apple", null, {
price : 5,
constructor : function(weight) {
this.total = weight * this.price;
},
// constructor : function() {
// alert("Create Apple !");
// },
print : function() {
alert("The total price is " + this.total);
}
}
);
dojo.declare("AppleTree", null, {
constructor : function() {
alert("Create AppleTree !");
},
print : function() {
alert("This is an apple tree");
},
additional : function() {
alert("This is a mixin class");
}
}
);
dojo.declare("GreenApple", [Apple, AppleTree], {
constructor : function() {
alert("Getting a green apple");
}
}
);
</script>
鍒涘緩涓涓狦reenApple瀵硅薄錛屾祴璇昦lert鎵ц欏哄簭錛乵ixin瀵硅薄鐨勬柟娉曞皢瑕嗙洊涔嬪墠瀵硅薄涓殑鍚屽悕鍑芥暟錛岄櫎闈炲瓙瀵硅薄涔熷0鏄庝簡鍚屽悕鍑芥暟print銆?
//杈撳嚭
//"The height of the tree is #ff0000"
//"Getting a green apple"
var gapple = new GreenApple();
//杈撳嚭錛岃鐩栦簡Apple瀵硅薄鐨刾rint
//"This is an apple tree"
gapple.print();
//"This is a mixin class"
gapple.additional();
dojo/_base/_loader/bootstrap.js鏈変笓闂ㄧ殑mixin鍑芥暟錛岀敤浜庡璞$殑鎷瘋礉錛屽皢涓涓垱寤哄ソ鐨勫璞℃嫹璐濆埌鏂扮殑瀵硅薄涓?
var copy = dojo.mixin({}, new Apple(2));
copy.print();
print杈撳嚭緇撴灉鏄?The total price is 10"錛宮ixin鍙傛暟涓瀹氭槸鍒涘緩濂界殑瀵硅薄瀹炰緥錛屽惁鍒欏嚭閿欙紒dojo.extend鍒欏彲浠ュ皢涓涓垨澶氫釜瀵硅薄鐨勫睘鎬с佹柟娉曟嫹璐濆埌涓涓師鍨嬩笂錛岄氳繃prototype瀹炵幇緇ф壙錛岃繖鏄戶鎵跨殑鍙﹀涓縐嶆柟寮忋?
閫氳繃declare銆乵ixin銆乪xtend錛?span class="hilite1">dojo緇欐垜浠彁渚涗簡涓縐嶆柟渚跨殑瀵硅薄鍒涘緩涓庢墿灞曟満鍒訛紝涓鑸儏鍐典笅澶熺敤浜嗭紝鎰熻榪樻槸姣旇緝鏂逛究錛屼嬌鐢ㄦ椂涔熷瓨鍦ㄤ竴浜涢檺鍒訛紝緲葷炕婧愪唬鐮佸氨鑳界悊瑙c傝繖閲屼富瑕佹槸瑕佺煡閬?span class="hilite1">dojo鏄浣曢潰鍚戝璞$殑錛屾柟渚挎垜浠洿濂界殑鐞嗚Вdojo鍩虹鍔熻兘錛屽強dijit鍜宒ojox錛?span class="hilite1">dojo鏈涓哄己澶ц繕鏄畠鐨剋idgets銆傛湰鏂囨秹鍙婄殑js婧愮爜錛?
mixin:dojo/_base/_loader/bootstrap.js
extend:dojo/_base/lang.js
declare:dojo/_base/declare.js
]]>
1錛氭敮鎸佸懡鍚嶇┖闂?/strong>
鍏朵腑
絳変環(huán)浜?nbsp;
2錛氭敮鎸佺被瀹炰緥灞炴?/strong>
// 涓鴻嚜瀹氫箟鐨勭被 澧炲姞涓涓?name 灞炴э紝騫惰祴鍊?br />
Ext.apply(Ext.wentao.Person.prototype, {
name : "鍒樻枃娑?
});
var _person = new Ext.wentao.Person();// 瀹炰緥鍖?鑷畾涔夌被
alert(_person.name);
_person.name = "寮犱笁";// 淇敼綾籲ame灞炴?br />
alert(_person.name);
3錛氭敮鎸佺被瀹炰緥鏂規(guī)硶
// 婕旂ず綾誨疄渚嬫柟娉?br />
Ext.apply(Ext.wentao.Person.prototype, {
name : "鍒樻枃娑?,
sex : "鐢?,
print : function() {
alert(String.format("濮撳悕:{0},鎬у埆:{1}", this.name, this.sex));
}
});
var _person = new Ext.wentao.Person();// 瀹炰緥鍖?鑷畾涔夌被
_person.print();
4錛氭敮鎸佺被闈欐佹柟娉?/strong>
Ext.namespace("Ext.wentao"); // 鑷畾涔変竴涓懡鍚嶇┖闂?br /> Ext.wentao.Person = Ext.emptyFn; // 鍦ㄥ懡鍚嶇┖闂翠笂鑷畾涔変竴涓被
// 婕旂ず綾誨疄渚嬫柟娉?br />
Ext.apply(Ext.wentao.Person.prototype, {
name : "鍒樻枃娑?,
sex : "鐢?,
print : function() {
alert(String.format("濮撳悕:{0},鎬у埆:{1}", this.name, this.sex));
}
});
// 婕旂ず 綾婚潤鎬佹柟娉?br />
Ext.wentao.Person.print = function(_name, _sex) {
var _person = new Ext.wentao.Person();
_person.name = _name;
_person.sex = _sex;
_person.print(); // 姝ゅ璋冪敤綾?瀹炰緥鏂規(guī)硶錛屼笂闈rint鏄被 闈欐佹柟娉?br />
};
Ext.wentao.Person.print("寮犱笁", "濂?); // 璋冪敤綾?闈欐佹柟娉?/p>
</script>
5錛氭敮鎸佹瀯閫犳柟娉?/strong>
6錛氭敮鎸佺被緇ф壙
Ext.namespace("Ext.wentao"); // 鑷畾涔変竴涓懡鍚嶇┖闂?/p>
// *******************鐖剁被*********************
// 鏋勯犳柟娉?br />
Ext.wentao.Person = function(_cfg) {
Ext.apply(this, _cfg);
};
// 婕旂ず綾誨疄渚嬫柟娉?br />
Ext.apply(Ext.wentao.Person.prototype, {
job : "鏃?,
print : function() {
alert(String.format("濮撳悕:{0},鎬у埆:{1},瑙掕壊:{2}", this.name,
this.sex, this.job));
}
});
// *******************瀛愮被1*********************
Ext.wentao.Student = function(_cfg) {
Ext.apply(this, _cfg);
};
Ext.extend(Ext.wentao.Student, Ext.wentao.Person, {
job : "瀛︾敓"
});
var _student = new Ext.wentao.Student({
name : "寮犱笁",
sex : "濂?
});
_student.print(); // 璋冪敤 鐖剁被鏂規(guī)硶
7錛氭敮鎸佺被瀹炰緥鏂規(guī)硶閲嶅啓
Ext.namespace("Ext.wentao"); // 鑷畾涔変竴涓懡鍚嶇┖闂?/p>
// *******************鐖剁被*********************
// 鏋勯犳柟娉?br />
Ext.wentao.Person = function(_cfg) {
Ext.apply(this, _cfg);
};
// 婕旂ず綾誨疄渚嬫柟娉?br />
Ext.apply(Ext.wentao.Person.prototype, {
job : "鏃?,
print : function() {
alert(String.format("濮撳悕:{0},鎬у埆:{1},瑙掕壊:{2}", this.name,
this.sex, this.job));
}
});
// *******************瀛愮被1*********************
Ext.wentao.Student = function(_cfg) {
Ext.apply(this, _cfg);
};
// 閲嶅啓鐖剁被鐨?瀹炰緥 鏂規(guī)硶
Ext.extend(Ext.wentao.Student, Ext.wentao.Person, {
job : "瀛︾敓",
print : function() {
alert(String.format("{0}鏄竴浣峽1}{2}", this.name, this.sex,
this.job));
}
});
var _student = new Ext.wentao.Student({
name : "寮犱笁",
sex : "濂?
});
_student.print(); // 璋冪敤 鐖剁被鏂規(guī)硶
8錛氭敮鎸佸懡鍚嶇┖闂村埆鍚?/strong>
Ext.namespace("Ext.wentao"); // 鑷畾涔変竴涓懡鍚嶇┖闂?/p>
Wt = Ext.wentao; // 鍛藉悕絀洪棿鐨勫埆鍚?/p>
// *******************鐖剁被*********************
// 鏋勯犳柟娉?br />
Wt.Person = function(_cfg) {
Ext.apply(this, _cfg);
};
// 婕旂ず綾誨疄渚嬫柟娉?br />
Ext.apply(Wt.Person.prototype, {
job : "鏃?,
print : function() {
alert(String.format("濮撳悕:{0},鎬у埆:{1},瑙掕壊:{2}", this.name,
this.sex, this.job));
}
});
// *******************瀛愮被1*********************
Wt.Student = function(_cfg) {
Ext.apply(this, _cfg);
};
// 閲嶅啓鐖剁被鐨?瀹炰緥 鏂規(guī)硶
Ext.extend(Wt.Student, Ext.wentao.Person, {
job : "瀛︾敓",
print : function() {
alert(String.format("{0}鏄竴浣峽1}{2}", this.name, this.sex,
this.job));
}
});
var _student = new Wt.Student({
name : "寮爍涓?,
sex : "濂?
});
_student.print(); // 璋冪敤 鐖剁被鏂規(guī)硶
9錛氭敮鎸佺被鍒悕
Ext.namespace("Ext.wentao"); // 鑷畾涔変竴涓懡鍚嶇┖闂?/p>
Wt = Ext.wentao; // 鍛藉悕絀洪棿鐨勫埆鍚?/p>
// *******************鐖剁被*********************
// 鏋勯犳柟娉?br />
Wt.Person = function(_cfg) {
Ext.apply(this, _cfg);
};
PN = Wt.Person; // 綾誨埆鍚?/p>
// 婕旂ず綾誨疄渚嬫柟娉?br />
Ext.apply(PN.prototype, {
job : "鏃?,
print : function() {
alert(String.format("濮撳悕:{0},鎬у埆:{1},瑙掕壊:{2}", this.name,
this.sex, this.job));
}
});
// *******************瀛愮被1*********************
Wt.Student = function(_cfg) {
Ext.apply(this, _cfg);
};
ST = Wt.Student;
// 閲嶅啓鐖剁被鐨?瀹炰緥 鏂規(guī)硶
Ext.extend(ST, PN, {
job : "瀛︾敓",
print : function() {
alert(String.format("{0}鏄竴浣峽1}{2}", this.name, this.sex,
this.job));
}
});
var _student = new ST({
name : "寮爍涓?,
sex : "濂?
});
_student.print(); // 璋冪敤 鐖剁被鏂規(guī)硶