javascriptдÀ෽ʽ֮Æß
7¡¢dojo.jsµÄдÀ෽ʽ
dojo×îÐÂÊÇ1.3.1ÁË£¬¼ÇµÃ07Äêʱ»¹ÊÇ0.4¡£ÎĵµÒ²½¥½¥¶àÁËÆðÀ´£¬ÓÃdojoµÄÒ²ÂýÂý¶àÁË¡£dojo»¹·¢²¼ÁËcore°æ£¬Ñ¹ËõºóÖ»ÓÐ
27kb¡£dojoÖÐÓÃdojo.declare·½·¨À´¶¨ÒåÒ»¸öÀà¡£dojo.declareµÄÔ´Âë¾Í²»ÌùÔÚÕâÀïÁË¡£dojo.declareÓÐÈý¸ö²Î
Êý£¬
²ÎÊý1£ºÀàÃûclassName
²ÎÊý2£º¼Ì³ÐµÄÀàsuperclass
²ÎÊý3£º¹¹ÔìÆ÷£¬·½·¨props
µ¥´¿µÄ¶¨ÒåÒ»¸öÀàʵ¼ÊÖ»Ðè´«µÚÒ»£¬ÈýÁ½¸ö²ÎÊý¡£ÒòΪÕâÀïÖ»ÌÖÂÛÈçºÎ¶¨ÒåÒ»¸öÀ࣬²»ÌÖÂۼ̳С£´úÂëÈçÏ£º
//¶¨ÒåÀàÃû
var className = "Person";
//¶¨Òå¹¹ÔìÆ÷¼°·½·¨
var proto = {
constructor : function(name){this.name=name;},
getName : function(){ return this.name;},
setName : function(name){ this.name = name;}
}
//¶¨ÒåÀàPerson
dojo.declare(className,null,proto);
//´´½¨Ò»¸ö¶ÔÏó
var p = new Person("tom");
console.log(p.getName());//tom
p.setName("jack");
console.log(p.getName());//jack
//²âÊÔinstanceof¼°p.constructorÊÇ·ñÕýÈ·Ö¸ÏòÁËPerson
console.log(p instanceof Person);//true
console.log(p.constructor === Person);//true
Ïà¹ØÎĵµ£º
±¾ÎÄÁоÙÁ˸÷ÖÖJavaScript¶ÔÏóÓëÊý×é,ͬʱ°üÀ¨¶ÔÉÏÊöÿһ¶ÔÏó»òÊý×éËùÍê³É¹¤×÷µÄ¼ò¶ÌÃèÊö,ÒÔ¼°ÓëÆäÏà¹ØµÄÊôÐÔ·½·¨,ÒÔ¼°Ê¼þ´¦Àí³ÌÐò¡£
¡¡¡¡B.1 anchor¶ÔÏó
¡¡¡¡Ê¹ÓÃ<A NAME=>±ê¼Ç´´½¨µÄHTMLÃèµãÄܱ»Ò»¸öÁ´½Ó×÷ΪĿ±êÈç¹ûêµã°üÀ¨HREF=ÌØÐÔ,ÔòËüÒ²ÊÇÒ»¸öÁ´½Ó¶ÔÏó¡£
¡¡¡¡anchor¶ÔÏóÊÇdocument¶ÔÏóµÄÒ»¸öÊôÐÔ,Ëü±¾Éíà ......
±¾ÎÄÁоÙÁ˸÷ÖÖJavaScript¶ÔÏóÓëÊý×é,ͬʱ°üÀ¨¶ÔÉÏÊöÿһ¶ÔÏó»òÊý×éËùÍê³É¹¤×÷µÄ¼ò¶ÌÃèÊö,ÒÔ¼°ÓëÆäÏà¹ØµÄÊôÐÔ·½·¨,ÒÔ¼°Ê¼þ´¦Àí³ÌÐò¡£
¡¡¡¡B.1 anchor¶ÔÏó
¡¡¡¡Ê¹ÓÃ<A NAME=>±ê¼Ç´´½¨µÄHTMLÃèµãÄܱ»Ò»¸öÁ´½Ó×÷ΪĿ±êÈç¹ûêµã°üÀ¨HREF=ÌØÐÔ,ÔòËüÒ²ÊÇÒ»¸öÁ´½Ó¶ÔÏó¡£
¡¡¡¡anchor¶ÔÏóÊÇdocument¶ÔÏóµÄÒ»¸öÊôÐÔ,Ëü±¾Éíà ......
//the common event,If your brower is firefox,you should use this function instead of "window.event"
function getEvent() {
if(document.all)
return window.event; //get ie event
func=getEvent.caller;
while(func!=null) {
......
function $id(s) {
return document.getElementById(s);
}
//ÅжÏСÊý
function IsFloat(s) {
if (!/^[+\-]?\d+(.\d+)?$/.test(s))
return false;
else
return ......
5¡¢Óà ¹¹Ô캯Êý+ÔÐÍ ¶¨ÒåÒ»¸öÀࣻͬһ¹¹Ô캯Êý¿ÉÒÔ¶¨Òå³ö¶à¸öÀàÐÍ
/**
* $define дÀ๤¾ßº¯ÊýÖ®¶þ
* @param {Object} constructor
* @param {Object} prototype
*/
function $define(constructor,prototype) {
var c = constructor || function(){};
var p = prototype || {};
r ......