Javascript ÃæÏò¶ÔÏó»úÖƵÄʵÏÖ
Javascript ÃæÏò¶ÔÏó»úÖƵÄʵÏÖ
×Ô¶¨ÒåÀàµÄʵÏÖ·½·¨ºÜ¶à£¬Öصã̸Á½ÖÖ¡£
¹¹Ô캯Êý·¨
function Player(url){
this.url = url;
this.showUrl = function(){
alert(this.url);
}
this.play = function(){
// do play
}
}
var myPlayer = new Player("test.mp3");
myPlayer.showUrl();
alert(myPlayer instanceof Player);
Óŵ㣺Àà±»·â×°³ÉÒ»¸öÕûÌå ÉùÃ÷ʵÀýÓÃnewÔËËã·û
ȱµã£º¶ÔÏóµÄ·½·¨»áÖظ´Éú³É
function Player(url){
this.url = url;
if(typeof Player._initialized == "undefined"){
Player.prototype.showUrl = function(){
alert(this.url);
Player._initialized = true;
}
}
}
var myPlayer = new Player("test.mp3");
myPlayer.showUrl();
alert(myPlayer instanceof Player);
Óŵ㣺±ÜÃâÁ˺¯ÊýµÄÖظ´´´½¨
ȱµã£ºÂé·³Ò»µã
·ÃÎÊȨÏÞ
JavaScript ±¾Éí²¢Ã»·¨Çø·Ö˽ÓбäÁ¿ºÍ¹«¹²±äÁ¿£¬Í¨³£ÔÚÃüÃûÉÏÇø·Öһϣ¬Ò»°ãÏ°¹ßÔÚ˽ÓбäÁ¿µÄÇ°¼ÓÒ»¸öÏ»®Ïß this._privateProperty¡£
ÓÐvarÉùÃ÷µÄ¾Ö²¿±äÁ¿¿ÉÒÔµ±×÷˽ÓбäÁ¿£¬thisÒýµ¼µÄΪ¹²ÓжÔÏó¡£
ʼþ
function Player(url){
this.url = url;
var self = this;
var position;
this.onPositionChange = null; // ʼþ¶¨Òå
this.setPosition = function(value){
self.position = value;
if (this.onPositionChange)
this.onPositionChange(this); //ʼþ´¥·¢
}
}
var myPlayer = new Player("test.mp3");
myPlayer.onPositionChange = function fun(obj){ //ʼþ¶©ÔÄ
alert(obj.position + 's Position Change');
}
myPlayer.setPosition(100);
ʵÀý»¯
¿É
Ïà¹ØÎĵµ£º
ÒýÑÔ
ÔÚJavaScriptÖÐÎÒÃÇʹÓÃÁËÒ»ÖÖ±»³ÆΪ JavaScript Object Notation(ËõдJSON)µÄÐÎʽ£¬·ÒëΪÖÐÎľÍÊÇ“JavaScript¶ÔÏó±íʾ·¨”¡£Ëü¿ÉÒÔ¼ò½éÇåÎúµØ½«¶ÔÏóµÄ½á¹¹ÃèÊö³öÀ´£¬´Ó¶ø´ó´ó½µµÍÁËÎÒÃǵŤ×÷Á¿²¢¼õÉÙÁËÊý¾ÝÁ¿¡£
JsonʾÀý
<script languag ......
ÒýÑÔ
prototypeÔ´×Ô·¨ÓÈí¼þ½çµÄ±ê×¼·ÒëΪ“ÔÐÍ”£¬´ú±íÊÂÎïµÄ³õʼÐÎ̬£¬Ò²º¬ÓÐÄ£ÐͺÍÑù°åµÄÒâÒå¡£
prototypeÊôÐÔ
JavaScriptµÄËùÓÐfunctionÀàÐ͵ĶÔÏó¶¼ÓÐÒ»¸öprototypeÊôÐÔ¡£Õâ¸öprototypeÊôÐÔ±¾ÉíÓÖÊÇÒ»¸ö object ÀàÐ͵ĶÔÏó£¬Òò´ËÎÒÃÇÒ²¿ÉÒÔ¸ ......
<input type=button value=ˢРonclick="window.location.reload()">
<input type=button value=Ç°½ø onclick="window.history.go(1)">
<input type=button value=ºóÍË onclick="window.history.go(-1)"> ......
JavaScript½øÐÐGETºÍPOSTÇëÇó
WebÉÏ×î³£¼ûµÄÇëÇó¾ÍÊÇGETÇëÇó.ÿ´ÎÔÚä¯ÀÀÆ÷ÖÐÊäÈëURL²¢´ò¿ªÒ²Ã×ÄÉÊÐ,¾ÍÊÇÔÚÏò·þÎñÆ÷·¢ËÍÒ»¸öGETÇëÇó.
GETÇëÇó£º
GETÇëÇóµÄ²ÎÊýʹÓÃÎʺÅ×·¼Óµ½URLµÄ½áβ,ºóÃ×ÄɸøÕâÓÃ&ºÃÁ¬½ÓÆðÀ´µÄÃû³Æ/Öµ.ÀýÈç:
http://www.somewhere.com/page.php?name1=value1&name2=value2&name3=value3
......
jsµÄFunction¶ÔÏóÔÚµ÷Óùý³ÌÖоßÓÐÒ»¸öarguomentsÊôÐÔ£¬ËüÊÇÓɽű¾½âÊÍÆ÷´´½¨µÄ£¬ÕâÒ²ÊÇ´´½¨arguments¶ÔÏóΨһ;¾¶¡£arguments¶ÔÏó¿ÉÒÔ¿´×öÊÇÒ»¸öArray¶ÔÏó£¬Ëü¾ßÓÐlengthÊôÐÔ£¬¿ÉÒÔͨ¹ýÐòºÅ·ÃÎÊÿһ¸ö²ÎÊý¡£¶øÇÒ£¬Í¨¹ýarguments µÄcalleeÊôÐÔ¿ÉÒÔ»ñÈ¡¶ÔÖ»ÔÚÖ´ÐеÄFunction¶ÔÏóµÄÒýÓã¬ÈçÏ ......