JavaScript ¼Ì³Ð
myhere
// ѧϰҪÏ뿽±´ÄÇô¿ì¾ÍºÃÁË
//
// JavaScript µÄ¼Ì³ÐÊÇ»ùÓÚ prototype µÄ£¬Ã¿¸ö¶ÔÏóµÄ prototype ÊDZ£´æÔÚ¶ÔÏóµÄ __proto__ ÊôÐÔÖеģ¬Õâ¸öÊôÐÔÊÇÄÚ²¿(internal)µÄÊôÐÔ( ¹ßÀýÊÇÄÚ²¿µÄ»òÕßÒþ²ØµÄÊôÐÔÒÔ _ ¿ªÍ·)
// A prototype-based language has the notion of a prototypical object, an object used as a template from which to get the initial properties for a new object.
//
/**
* Property lookup in Javascript looks within an object's own properties and,
* if the property name is not found, it looks within the special object property __proto__.
* This continues recursively; the process is called "lookup in the prototype chain".
* The special property __proto__ is set when an object is constructed;
* it is set to the value of the constructor's prototype property.
* So the expression new Foo() creates an object with __proto__ == Foo.prototype.
* Consequently, changes to the properties of Foo.prototype alters the property lookup for all objects that were created by new Foo().
*/
// ¸ø¶ÔÏóµÄÔÐÍÔö¼Ó³ÉÔ±»áÁ¢¼´ÔڸöÔÏóÖпɼû
function Base(){
this.name = 'myhere';
}
function Sub(){
this.age = 23;
}
Sub.prototype = new Base(); // ¸øÔÐ͸³ÖµÎªÒ»¸ö==¶ÔÏó==¡£
var me = new Sub();
// ´´½¨¶ÔÏóºó¸øÔÐÍÔö¼Ó sex ÊôÐÔ£¬¸ÃÊôÐÔÁ¢¼´ÔÚ¶ÔÏóÖпɼû
Base.prototype.sex = 'male';
var str = '';
str += me.name + me.age + me.sex;
document.write( str); // myhere23male
/**
* ˵Ã÷£º
* ¶ÔÓÚÕâÖּ̳У¬ÔÚÆµ·±ÐÞ¸ÄÔÐ͵ÄÇé¿öϾͱäµÃ»ìÂÒÁË
*/
//
/**
* ÁíÒ»Öּ̳з½·¨
*/
function Base(){
this.name = 'myhere';
}
// ²¢Ã»Óн« Sub µÄÔÐ͸³ÖµÎª Base£¬Ö»ÊÇÔÚ Sub Öе÷Óà Base º¯Êý
function Sub(){
this.age = 23;
Base.call( this); // Ö»Êǽ«Ò»²¿·Ö³õʼ»¯½»¸ø Base º¯Êý£¬²¢Ã»ÓвÙ×÷ prototype
}
var me = new Sub();
Base.prototype.sex = 'male'; // ÐÞ¸Ä Base ²»»áÓ°Ïì Sub µÄ¶ÔÏó£¬ÒòΪ Base ²¢²»ÊÇ Sub µÄÔÐÍ
// Èç¹û½«Õâ¸öÔö¼Ó sex µÄÓï¾ä·Åµ½ Sub ¶¨Òåǰ£¬ÔÚ me ÖÐÒ²µÃ²»µ½ sex ÊôÐÔ£¬
// ÒòΪ Base.call() Ö»Êǵ÷Óà Base º¯Êý¶øÒÑ
var str = '';
str += me.name + m
Ïà¹ØÎĵµ£º
¾³£ÔÚie6ϳöÏÖjavascriptÒ³ÃæÌø×ªºÍ±íµ¥Ìá½»ÎÊÌ⣬ie6ÏÂʵÏÖjavascriptÒ³ÃæÌø×ªºÍ±íµ¥Ìá½»ÐèÒª½øÐÐÌØ±ð´¦Àí£¬ÐèҪʹÓÃsetTimeout()º¯ÊýÑÓ³ÙʵÏÖ¡£
1£¬¼æÈݸ÷ä¯ÀÀÆ÷µÄJavascriptÒ³ÃæÌø×ª
setTimeout(function(){
window.location.href = url;
},0);
2£¬¼æÈݸ÷ä¯ÀÀÆ÷µÄJavascript±íµ¥Ìá½»
setTimeout(function ......
Dojo
Ò»¸öÇ¿´óµÄÃæÏò¶ÔÏójavascript¿ò¼Ü¡£
Ö÷ÒªÓÉÈý´óÄ£¿é×é³É£ºCore¡¢Dijit¡¢DojoX¡£
CoreÌṩ Ajax£¬events£¬packaging£¬CSS-based querying£¬animations£¬JSONµÈÏà¹Ø²Ù×÷API¡£
Dijit ......
1. javascript ÊÇÇø·Ö´óСдµÄ£¬°üÀ¨±äÁ¿¡¢º¯ÊýÃûµÈµÈ¡£
2. javascript ÖеıäÁ¿ÊÇÈõÀàÐ͵쬶¨Òå±äÁ¿Ê±Ö»Óà var ÔËËã·û¡£
var test1 = "hi";
»òÕß
var test1 = "hi",test2 = "hello";
»òÕß(¿ÉÒÔÊDz»Í¬µÄÀàÐÍ)
var test1 = "hi",test2 = 12;
»òÕß(¿ÉÒÔ²»Óóõʼ»¯)
var test1;
3. javascript ÿÌõÓï¾äµÄ½áβ&ldqu ......
javascript²Ù×÷¸´Ñ¡¿òº¯Êý
function CheckAll(form) {//ȫѡ
for (var i=0;i var e = form.elements[i];
if (e.name != 'chkall')
e.checked = form.chkall.checked;
}
}
function checkSelect()//ÅжÏÊÇ·ñÓÐÑ¡ ......
²»Óò»ÖªµÀ,Ò»ÓòÅÖªµÀÕâÁ½ÕßÊDz»´óÒ»ÑùµÄ,ÏñÔÚjavaÖÐ,ÊÇÖ±½ÓʹÓà ,Èç str1.replace("$","*") °Ñ$ºÅ±ä³É*ºÅ
µ«ÔÚjavascript¾Í²»Ò»Ñù,ҪʵÏÖÉÏÃæµÄ¹¦ÄÜÊÇÕâÑùд: str.replace(/&/g,"*") ÆäÖеÄgÊDzÎÊý,˵Ã÷Òª½«È«²¿µÄ$¶¼±ä³É*
ÏÂÃæ°ÑjavascriptµÄÕ³ÌùÔÚÏÂÃæ:
¶¨ÒåºÍÓ÷¨
replace() ·½·¨ÓÃÓÚÔÚ×Ö·û´®ÖÐÓÃһЩ×Ö·ûÌ ......