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;
}
Ïà¹ØÎĵµ£º
±¾ÎÄÖ÷ÒªÊdzöÓÚÓÐÅóÓÑʹÓÃÎÒÔÀ´Ð´µÄautocompleteµÄJS¿Ø¼þ¡£µ±Êý¾ÝÁ¿´óµÄʱºò£¬»á³öÏÖЧÂʼ«ÆäÂýµÄÇé¿ö£¬ÎÒÔÚÕâ¶Îʱ¼ä×ö³öµÄһЩ²âÊÔÒ²¼°Ò»Ð©¾Ñ飬Óë´ó¼Ò·ÖÏí£¬Èç¹ûÓдíµÄµØ·½£¬»¹ÇëÖ¸³ö¡£
¾¹ý²âÊÔ£¬ÎÒÃǻᷢÏÖÈçϵÄÇé¿ö»òÕß˵µÄ½áÂÛ£¬Èç¹ûÄúµÄ²âÊÔ½á¹ûÓëÎҵIJ»·û£¬Çë˵Ã÷ÔÒò£¬ÒÔ±ãÏ໥ѧϰ¡£
1£©µ±Ò»¸ö½Ï´óµÄHTML×Ö· ......
calcu() ----º¯ÊýʵÏÖÁ½¸öÊýÏà³Ë
document.write(); ---´òÓ¡
document.calc.ÔªËØÃû.value; --»ñµÃ±íµ¥µÄÖµ
document.±íµ¥Ãû¡£±íµ¥ÔªËØÃû¡£value Ϊ±íµ¥¸³Öµ
¶¨Ò庯Êý£º
function Ãû×Ö()
{
//javaScriptÔ¤Óï¾ä
}
onClick="º¯ÊýÃû";  ......
Dynamic Script Elements ¶¯Ì¬½Å±¾ÔªËØ
The Document Object Model (DOM) allows you to dynamically create almost any part of an HTML document using JavaScript. At its root, the <script> element isn't any different than any other element on a page: references can be retrie ......
µÚ¶þÕ Data Access Êý¾Ý·ÃÎÊ
One of the classic computer science problems is determining where data should be stored for optimal reading and writing. Where data is stored is related to how quickly it can be retrieved during code execution. This problem in JavaScri ......
È¡Ç°ÃæÁ½ÖÖµÄÓŵ㣺
a¡¢Óù¹Ô캯ÊýÀ´¶¨ÒåÀàÊôÐÔ£¨×ֶΣ©
b¡¢ÓÃÔÐÍ·½Ê½À´¶¨ÒåÀàµÄ·½·¨¡£
¾ÍÓÐÁ˵ÚÈýÖÖ·½Ê½¡£ÕâÖÖ·½Ê½Ã²ËƲÉÓõÄÈ˽϶ࡣ
3¡¢×ۺϹ¹Ô캯Êý/ÔÐÍ
/**
* PersonÀࣺ¶¨ÒåÒ»¸öÈË£¬ÓиöÊôÐÔname£¬ºÍÒ»¸ögetName·½·¨
* @param {String} name
*/
function Person(name) {
this.name = name;
}
Pers ......