JavaScript ¼Ì³ÐÏê½â2
ÕâÒ»ÕÂÎÒÃǽ«»áÖصã½éÉÜJavaScriptÖм¸¸öÖØÒªµÄÊôÐÔ£¨this¡¢constructor¡¢prototype£©£¬ ÕâЩÊôÐÔ¶ÔÓÚÎÒÃÇÀí½âÈçºÎʵÏÖJavaScriptÖеÄÀàºÍ¼Ì³ÐÆð×ÅÖÁ¹ØÖØÒªµÄ×÷Óá£
this
this±íʾµ±Ç°¶ÔÏó£¬Èç¹ûÔÚÈ«¾Ö×÷Ó÷¶Î§ÄÚʹÓÃthis£¬ÔòÖ¸´úµ±Ç°Ò³Ãæ¶ÔÏówindow£» Èç¹ûÔÚº¯ÊýÖÐʹÓÃthis£¬ÔòthisÖ¸´úʲôÊǸù¾ÝÔËÐÐʱ´Ëº¯ÊýÔÚʲô¶ÔÏóÉϱ»µ÷ÓᣠÎÒÃÇ»¹¿ÉÒÔʹÓÃapplyºÍcallÁ½¸öÈ«¾Ö·½·¨À´¸Ä±äº¯ÊýÖÐthisµÄ¾ßÌåÖ¸Ïò¡£
ÏÈ¿´Ò»¸öÔÚÈ«¾Ö×÷Ó÷¶Î§ÄÚʹÓÃthisµÄÀý×Ó£º
<script type="text/javascript">
console.log(this === window); // true
console.log(window.alert === this.alert); // true
console.log(this.parseInt("021", 10)); // 10
</script>
º¯ÊýÖеÄthisÊÇÔÚÔËÐÐʱ¾ö¶¨µÄ£¬¶ø²»ÊǺ¯Êý¶¨Òåʱ£¬ÈçÏ£º
// ¶¨ÒåÒ»¸öÈ«¾Öº¯Êý
function foo() {
console.log(this.fruit);
}
// ¶¨ÒåÒ»¸öÈ«¾Ö±äÁ¿£¬µÈ¼ÛÓÚwindow.fruit = "apple";
var fruit = "apple";
// ´Ëʱº¯ÊýfooÖÐthisÖ¸Ïòwindow¶ÔÏó
// ÕâÖÖµ÷Ó÷½Ê½ºÍwindow.foo();ÊÇÍêÈ«µÈ¼ÛµÄ
foo(); // "apple"
// ×Ô¶¨ÒåÒ»¸ö¶ÔÏ󣬲¢½«´Ë¶ÔÏóµÄÊôÐÔfooÖ¸ÏòÈ«¾Öº¯Êýfoo
var pack = {
fruit: "orange",
foo: foo
};
// ´Ëʱº¯ÊýfooÖÐthisÖ¸Ïòwindow.pack¶ÔÏó
pack.foo(); // "orange"
È«¾Öº¯ÊýapplyºÍcall¿ÉÒÔÓÃÀ´¸Ä±äº¯ÊýÖÐthisµÄÖ¸Ïò£¬ÈçÏ£º
// ¶¨ÒåÒ»¸öÈ«¾Öº¯Êý
function foo() {
console.log(this.fruit);
}
// ¶¨ÒåÒ»¸öÈ«¾Ö±äÁ¿
var fruit = "apple";
// ×Ô¶¨ÒåÒ»¸ö¶ÔÏó
var pack = {
fruit: "orange"
};
// µÈ¼ÛÓÚwindow.foo();
foo.apply(window); // "apple"
// ´ËʱfooÖеÄthis === pack
foo.apply(pack); // "orange"
×¢£ºapplyºÍcallÁ½¸öº¯ÊýµÄ×÷ÓÃÏàͬ£¬Î¨Ò»µÄÇø±ðÊÇÁ½¸öº¯ÊýµÄ²ÎÊý¶¨Ò岻ͬ¡£
ÒòΪÔÚJavaScriptÖк¯ÊýÒ²ÊǶÔÏó£¬ËùÒÔÎÒÃÇ¿ÉÒÔ¿´µ½ÈçÏÂÓÐȤµÄÀý×Ó£º
// ¶¨ÒåÒ»¸öÈ«¾Öº¯Êý
function foo() {
if (this === window) {
console.log("this is window.");
}
Ïà¹ØÎĵµ£º
×ֺţº´ó ÖРС
·½·¨Ò»£º×µÄ£¬×îÈÝÒ×Àí½âµÄ£¬ÇÒ¿ÉÒÔËæÒâÉèÖÃÒªÅųýµÄ×Ö·û
<script language="javascript">
function isChinese1(str){
var badChar ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
badChar += "abcdefghijklmnopqrstuvwxyz";
badChar += "0123456789";
badChar += " "+"¡¡";//°ë½ÇÓëÈ«½Ç¿Õ¸ñ
badChar ......
Ô´´ÓÚ2007Äê12ÔÂ16ÈÕ£¬2009Äê10ÔÂ15ÈÕǨÒÆÖÁ´Ë¡£
JavaScriptͨ¹ýÄÚÖõÄsetTimeoutº¯ÊýÀ´Íê³ÉÒ³ÃæÄڵĶ¨Ê±¼ì²é£¬Ò²ÊǺܾÃÒÔǰдµÄ¶«Î÷ÁË¡£
Ö®ËùÒÔÏëÆðËüÀ´£¬ÊÇÒòΪÔÚºÍÏîÄ¿×éÆäËû³ÉԱ˵¸ÃÊÂÇéµÄʱºò£¬±ðÈ˾¹È»³°Ð¦ÎÒ˵ÊÇÉϸöÊÀ¼ÍµÄ´úÂ룬ÏÖÔÚ¶¼ÓÃWEB2.0ÁË¡£
<script language="JavaScript" type="text ......
Ëæ×Å»¥ÁªÍøµÄ·ÉËÙ·¢Õ¹£¬µØÇò±äµÃÔ½À´Ô½Ð¡£¬ÈËÃÇ¿ÉÒÔ¿çԽʱ¼äºÍ¿Õ¼äµÃ½çÏÞ½øÐн»Á÷ÓÚºÏ×÷¡£µ«ÊÇËæÖ®Ò²²úÉúÁËһЩËÁÒâ¸ãÆÆ»µµÄºÚ¿Í£¬Õâ¾ÍʹµÃ³ÌÐòÉè¼ÆÈËÔ±ÔÚ±àÖÆÓ¦ÓóÌÐòÖÐÒª¿¼Âǵ½ºÚ¿ÍÏ®»÷Õâ¸öÎÊÌ⣬ËùÒÔ×ÔÈ»¶øÈ»µØ¾Í»áÏëµ½±£»¤¡£±¾½Ú½Ì³Ì½«½ÌÄãÔõÑùÀûÓÃjavascript½øÐÐÃÜÂë±£»¤¡£ÀûÓà JavaScriptÀ´¶ÔÍøÒ³½øÐÐÃÜÂë±£»¤Óм¸ÖÖ· ......
EclipseдjavascriptÊDZȽÏÍ´¿àµÄ,ÓÐÁËjsEclipseÕâ¸öÇ¿´óµÄjavascript±à¼²å¼þ¾Í·½±ã¶àÁË,Õâ¸ö²å¼þÖ§³Ö´úÂëÍê³É,´ó¸Ùä¯ÀÀ,´íÎ󱨸æ,´úÂë»»ÐеȵÈ.
°²×°jsEclipseºÜ·½±ã,ͨ¹ýHELP-Software Updates-Find and Install ÔÚURLÖмÈëhttp://www.interaktonline. ......