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¾ÍÊÇ°ÑÊý¾ÝºÍ´úÂ붼¼ò»¯µ½×îÔʼµÄ³Ì¶È¡£
»ù±¾ÀàÐÍ
Ò»¡¢¼òµ¥Êý¾ÝÀàÐÍ£ºundefined¡¢null¡¢boolean¡¢number¡¢string£¨×¢Ò⣺¶¼Ê ......
Íæ͸javascriptµ¯³ö´°¿Ú
--------------------------------------------------------------------------------
¡¡¡¡¾³£ÉÏÍøµÄÅóÓÑ¿ÉÄܻᵽ¹ýÕâÑùһЩÍøÕ¾£¬Ò»½øÈëÊ×Ò³Á¢¿Ì»áµ¯³öÒ»¸ö´°¿Ú£¬»òÕß°´Ò»¸öÁ¬½Ó»ò°´Å¥µ¯³ö£¬Í¨³£ÔÚÕâ¸ö´°¿ÚÀï»áÏÔʾһЩעÒâÊÂÏî¡¢°æȨÐÅÏ¢¡¢¾¯¸æ¡¢»¶Ó¹â¹ËÖ®ÀàµÄ»°»òÕß×÷ÕßÏëÒªÌرðÌáʾµ ......
ÎÒÃǶ¼ÖªµÀjava¡¢c#¡¢vbµÈÓïÑÔ¶¼ÓÐsleepÔÝÍ£µÄº¯Êý£¬¶øJavaScript½Å±¾Ã»ÓÐÀàËƵŦÄÜ¡£
ÏÂÃæ¾ÍÊÇÎÒµÄʵÏֵķ½·¨£º
<mce:script type="text/javascript"><!--
function test()
{
var s="javascript--ÔÝÍ£º¯Êý";
setTimeout(
function(){
eval(sleep(test)); //Ö´ÐÐreturnÖ®ºóµÄ´úÂ룬Ҳ¾ÍÊÇ&ldq ......
ÿһÏÊÇjsÖеÄС¼¼ÇÉ£¬µ«Ê®·ÖµÄʵÓã¡
1.document.write(""); Êä³öÓï¾ä
2.JSÖеÄ×¢ÊÍΪ//
3.´«Í³µÄHTMLÎĵµË³ÐòÊÇ:document->html->(head,body)
4.Ò»¸öä¯ÀÀÆ÷´°¿ÚÖеÄDOM˳ÐòÊÇ:window->(navigator,screen,history,location,document)
5.µÃµ½±íµ¥ÖÐÔªËصÄÃû³ÆºÍÖµ:document.getElementById("±íµ¥ÖÐÔªËØµÄ ......
¼òµ¥µÄÀý×Ó£¬×Ô¼º¿´¿´£¬Ê¡µÃÒÔºóÀÏÊÇÈ¥ÕÒÁË¡£
<script language="javascript">
//ÓÃÕýÔòÌæ»»½«XÌæ»»³Éy
var s="daxdasx";//Ô×Ö·û´®
var k="x";//±»Ìæ»»µÄ×Ö¶Î
var re = new RegExp(k,"g");
alert("Ì滻ǰ×Ö·û´®Îª£º"+s);
s = s.replace(re,"y");
alert("Ìæ»»ºó×Ö·û´®Îª£º"+s);
</script> ......