javascriptдÀ෽ʽ֮ËÄ
ͨ¹ýÇ°Ãæ¼¸ÆªµÃÖªjavascriptдÀàÎÞ·Ç»ùÓÚ¹¹Ô캯Êý
ºÍÔÐÍ
¡£¼ÈÈ»ÕâÑù£¬ÎÒÃÇд¸ö¹¤¾ßº¯ÊýÀ´Ð´Àà¡£
/**
* $class дÀ๤¾ßº¯ÊýÖ®Ò»
* @param {Object} constructor
* @param {Object} prototype
*/
function $class(constructor,prototype) {
var c = constructor || function(){};
var p = prototype || {};
c.prototype = p;
return c;
}
àÅ¡£¹¤¾ßÀàдºÃÁË£¬À´×é×°Ï£ºÓù¹Ô캯ÊýÀ´Éú³ÉÀàʵÀýµÄÊôÐÔ£¨×ֶΣ©£¬ÔÐͶÔÏóÓÃÀ´Éú³ÉÀàʵÀýµÄ·½·¨¡£
//¹¹Ô캯Êý
function Person(name) {
this.name = name;
}
//ÔÐͶÔÏó
var proto = {
getName : function(){return this.name},
setName : function(name){this.name = name;}
}
//×é×°
var Man = $class(Person,proto);
var Woman = $class(Person,proto);
ok£¬ÕâʱºòÒѾµÃµ½ÁËÁ½¸öÀàMan£¬Woman¡£²¢ÇÒÊÇͬһ¸öÀàÐ͵ġ£²âÊÔÈçÏ£º
console.log(Man == Woman);//true
console.log(Man.prototype == Woman.prototype);//true
´´½¨¶ÔÏó¿´¿´£¬
var man = new Man("Andy");
var woman = new Woman("Lily");
console.log(man instanceof Man);//true
console.log(woman instanceof Woman);//true
console.log(man instanceof Person);//true
console.log(woman instanceof Person);//true
okÒ»ÇÐÈçÎÒÃÇËùÆÚÍû¡£µ«ÊÇÓиöÎÊÌ⣬ÏÂÃæ´úÂëµÄ½á¹ûÊä³öfalse£¬
console.log(man.constructor == Person);//false
ÕâÈÃÈ˲»Ô㺴ÓÒÔÉϵĴúÂë¿´³ömanµÄÈ·ÊÇͨ¹ýManÀànew³öÀ´µÄ var man = new Man("Andy")£¬ÄÇô¶ÔÏóʵÀýmanµÄ¹¹ÔìÆ÷Ó¦¸ÃÖ¸ÏòMan£¬µ«ÎªºÎÊÂÓëÔ¸Î¥ÄØ£¿
ÔÒò¾ÍÔÚÓÚ$classÖÐÖØÐ´ÁËPersonµÄÔÐÍ£ºc.prototype = p;
ºÃÁË£¬ÎÒÃǰÑ$classÉÔ΢¸ÄдÏ£¬½«·½·¨¶¼¹ÒÔÚ¹¹ÔìÆ÷µÄÔÐÍÉÏ£¨¶ø²»ÊÇÖØÐ´¹¹ÔìÆ÷µÄÔÐÍ£©£¬ÈçÏ£º
function $class(constructor,prototype) {
var c = constructor || function(){};
var p = prototype || {};
// c.prototype = p;
for(var atr in p)
c.prototype[atr] = p[atr];
return c;
}
Ïà¹ØÎĵµ£º
Grouping Scripts ³É×é½Å±¾
Since each <script> tag blocks the page from rendering during initial download, it's helpful to limit the total number of <script> tags contained in the page. This applies to both inline scripts as well as those in external files. Every time ......
ȺÀïÌÖÂÛ¹ýµÄÌâÄ¿£¬·ÖÏíһϡ£
function test(){
var m=n=1;
alert(m);
}
alert(n);
//ÒòΪtestº¯ÊýûÓÐÖ´ÐУ¬³Ì¶È¿ØÖÆÁ÷²»ÄܽøÈë½øÐнâÎö£¬ÀïÃæµÄ¶«Î÷¶ÔÍâÃæ²»¿É¼û£¬Òò´Ë±¨´í
function test(){
var m=n=1;
alert(m);
}
test();
alert(n);
//µ±testÖ´Ðкó£¬Í ......
ÔÚjavascriptº¯ÊýÌåÄÚ£¬±êʶ·ûarguments¾ßÓÐÌØÊ⺬Òå¡£ËüÊǵ÷ÓöÔÏóµÄÒ»¸öÌØÊâÊôÐÔ£¬ÓÃÀ´ÒýÓÃArguments¶ÔÏó¡£Arugments¶ÔÏó¾ÍÏñÊý×飬עÒâÕâÀïÖ»ÊÇÏñ²¢²»Êǹþ¡£
javascriptº¯ÊýÌåÄÚ£¬argumentsÏñÊý×é(²¢²»ÊÇÕæµÄÊý×飬ÊÇÒ»¸öArguments¶ÔÏó£¬ÔÙ´ÎÇ¿µ÷)Ò»Ñù£¬ÓÐlengthÊôÐÔ£¬¿ÉÒÔ´ú±í´«¸øº¯ÊýµÄ²ÎÊýµÄ¸öÊý¡£
ÒýÓÃÒ»¸öÐÎʽ²ÎÊ ......
1¡¢IsStartupScriptRegistered£º¶ÔÏóÊÇ·ñ×¢²áÁËÆôÓýű¾¡£
2¡¢IsClientScriptBlockRegistered£º¶ÔÏóÊÇ·ñ×¢²áÁ˿ͻ§¶Ë½Å±¾¿é¡£
3¡¢IsClientScriptIncludeRegistered£º¶ÔÏóÊÇ·ñ×¢²áÁ˿ͻ§¶Ë½Å±¾°üº¬¡£
µÚÒ»¸öÀý×Ó£º
string info = "<script>alert('ÄãºÃÂð£¿');</script>";
//ÅжÏʼþÊÇ·ñ±»×¢²á£¬Ð´ÈëÇ ......