Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JavaScript apply¡¢call·½·¨ºÍlengthÊôÐÔ

JavaScriptΪº¯Êý¶ÔÏó¶¨ÒåÁËÁ½¸ö·½·¨£ºapplyºÍcall£¬ËüÃǵÄ×÷Óö¼Êǽ«º¯Êý°ó¶¨µ½ÁíÍâÒ»¸ö¶ÔÏóÉÏÈ¥ÔËÐУ¬Á½Õß½öÔÚ¶¨Òå²ÎÊýµÄ·½Ê½ÓÐËùÇø±ð£º
Function.prototype.apply(thisArg,argArray);
Function.prototype.call(thisArg[,arg1[,arg2…]]);
´Óº¯ÊýÔ­ÐÍ¿ÉÒÔ¿´µ½£¬µÚÒ»¸ö²ÎÊý¶¼±»È¡ÃûΪthisArg£¬¼´ËùÓк¯ÊýÄÚ²¿µÄthisÖ¸Õ붼»á±»¸³ÖµÎªthisArg£¬Õâ¾ÍʵÏÖÁ˽«º¯Êý×÷ΪÁíÍâÒ»¸ö¶ÔÏóµÄ·½·¨ÔËÐеÄÄ¿µÄ¡£Á½¸ö·½·¨³ýÁËthisArg²ÎÊý£¬¶¼ÊÇΪFunction¶ÔÏ󴫵ݵIJÎÊý¡£ÏÂÃæµÄ´úÂë˵Ã÷ÁËapplyºÍcall·½·¨µÄ¹¤×÷·½Ê½£º
function func1(){
      this.p="func1-";
      this.A=function(arg){
            alert(this.p+arg);
      }
}
function func2(){
      this.p="func2-";
      this.B=function(arg){
             alert(this.p+arg);
      }
}
var obj1=new func1();
var obj2=new func2();
obj1.A("byA");     //ÏÔʾfunc1-byA
obj2.B("byB");     //ÏÔʾfunc2-byB
obj1.A.apply(obj2,["byA"]); //ÏÔʾfunc2-byA£¬ÆäÖÐ[“byA”]ÊǽöÓÐÒ»¸öÔªËصÄÊý×飬ÏÂͬ
obj2.B.apply(obj1,["byB"]); //ÏÔʾfunc1-byB
obj1.A.call(obj2,"byA");   //ÏÔʾfunc2-byA
obj2.B.call(obj1,"byB");   //ÏÔʾfunc1-byB
¿ÉÒÔ¿´³ö£¬obj1µÄ·½·¨A±»°ó¶¨µ½obj2ÔËÐкó£¬Õû¸öº¯ÊýAµÄÔËÐл·¾³¾ÍתÒƵ½ÁËobj2£¬¼´thisÖ¸ÕëÖ¸ÏòÁËobj2¡£Í¬Ñùobj2µÄº¯ÊýBÒ²¿ÉÒ԰󶨵½obj1¶ÔÏóÈ¥ÔËÐС£´úÂëµÄ×îºó4ÐÐÏÔʾÁËapplyºÍcallº¯Êý²ÎÊýÐÎʽµÄÇø±ð¡£
ÓëargumentsµÄlengthÊôÐÔ²»Í¬£¬º¯Êý¶ÔÏó»¹ÓÐÒ»¸öÊôÐÔlength£¬Ëü±íʾº¯Êý¶¨ÒåʱËùÖ¸¶¨²ÎÊýµÄ¸öÊý£¬¶ø·Çµ÷ÓÃʱʵ¼Ê´«µÝµÄ²ÎÊý¸öÊý¡£ÀýÈçÏÂÃæµÄ´úÂ뽫ÏÔʾ2£º
function sum(a,b){
      return a+b;
}
alert(sum.length);


Ïà¹ØÎĵµ£º

¡¾×ª¡¿javascriptÕýÔò±í´ïʽµÄ³£Ó÷½·¨×ܽá

´úÂëʹÓ÷½·¨£º
ÔÚ½éÉÜÕýÔò±í´ïʽÓ﷨֮ǰÏÈѧϰÏÂÃ漸¸ö·½·¨:
ÕýÔò±í´ïʽ·½·¨:test(),exec()
String¶ÔÏó·½·¨:match(),search(),replace(),split()
test()·½·¨:
Ó÷¨:regexp¶ÔÏóʵÀý.test(×Ö·û´®)
·µ»ØÖµ:Èç¹ûÂú×ãregexp¶ÔÏóʵÀýÖж¨µÄÕýÔò¹æÔò,·µ»Øtrue,·ñÔò·µ»Øfalse
exec()·½·¨:
......

javascriptÖÐsubstr,substring,slice.spliceµÄÇø±ð

substr() ·½·¨¿ÉÔÚ×Ö·û´®ÖгéÈ¡´Ó start ϱ꿪ʼµÄÖ¸¶¨ÊýÄ¿µÄ×Ö·û.
stringObject.substr(start,length);start±ØÐë,length¿ÉÑ¡.
start ÊǽØÈ¡µÄ¿ªÊ¼Î»ÖõÄϱê,´Ó0¿ªÊ¼ËãÆð,±ØÐëÊÇÊý×Ö.¿ÉÒÔÊǸºÊý,-1Êǵ¹ÊýµÚÒ»¸ö×Ö·û,-2Êǵ¹ÊýµÚ¶þ¸ö×Ö·û,ÒÔ´ËÀàÍÆ.
length ÊÇÒª½ØÈ¡µÄ×Ö·ûµÄ³¤¶È,±ØÐëÊÇÊý×Ö.Èç¹ûδָ¶¨,Ôò´ÓstartλÖô¦¿ ......

javascript µÄ±Õ°ü

±Õ°ü£¨closure£©ÊÇJavascriptÓïÑÔµÄÒ»¸öÄѵ㣬ҲÊÇËüµÄÌØÉ«£¬ºÜ¶à¸ß¼¶Ó¦Óö¼ÒªÒÀ¿¿±Õ°üʵÏÖ¡£
ÏÂÃæ¾ÍÊÇÎÒµÄѧϰ±Ê¼Ç£¬¶ÔÓÚJavascript³õѧÕßÓ¦¸ÃÊǺÜÓÐÓõġ£
Ò»¡¢±äÁ¿µÄ×÷ÓÃÓò
ÒªÀí½â±Õ°ü£¬Ê×ÏȱØÐëÀí½âJavascriptÌØÊâµÄ±äÁ¿×÷ÓÃÓò¡£
±äÁ¿µÄ×÷ÓÃÓòÎ޷ǾÍÊÇÁ½ÖÖ£ºÈ«¾Ö±äÁ¿ºÍ¾Ö²¿±äÁ¿¡£
JavascriptÓïÑÔµÄÌØÊâÖ®´¦£¬¾ÍÔÚÓ ......

×Ô¶¯µãÍøÒ³ÖеÄJavaScriptÁ´½Ó


‘µãÕý³£Á´½Ó·½·¨ºÜ¶à£¬ÕâÀï½éÉܵÄÊÇ×Ô¶¯µãJavaScriptÁ´½Ó
Function RunJS(scripts)
‘VB ×Ô¶¯µãÍøÒ³ÖеÄJavascriptÁ´½Ó
Dim Document
                On Error GoTo ErrHandle
        ......

ÈçºÎÔÚjavascriptÖзÃÎÊÒ³Ã涨ÒåµÄ±äÁ¿

¡¾×ª¡¿http://www.cnblogs.com/chenxizhang/archive/2010/01/01/1637309.html
Èç¹ûÎÒÃÇÐèÒªÔÚjavascript·ÃÎʵ½Ò³ÃæÖж¨ÒåµÄ±äÁ¿£¬´óÖÂÊÇÈçϵÄÓï·¨
//ÕâÊÇ2010Äê1ÔÂ1ÈÕÔö¼ÓµÄ´úÂë
var ismanager = "<%= DepartManager %>";
if (ismanager == "true") {
$(" ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ