HTML5¼¼Êõ

JavaScriptÃæÏò¶ÔÏó(OOP) - ½ã½ãjy(3)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-10-15 08:12 ÎÒÒªÆÀÂÛ( )

function func(){console.log( this );} var obj= {name: "zhangsan" ,func:func} // ¢Ùͨ¹ýº¯ÊýÃû()µ÷Óõģ¬thisÓÀÔ¶Ö¸Ïòwindow¡£ func(); // ¢Úͨ¹ý¶ÔÏó.·½·¨µ÷Óõģ¬thisÖ¸ÏòÕâ¸ö¶ÔÏó obj.func(); // ÏÁÒå¶ÔÏó w

function func(){ console.log(this); } var obj={ name:"zhangsan", func:func } //¢Ùͨ¹ýº¯ÊýÃû()µ÷Óõģ¬thisÓÀÔ¶Ö¸Ïòwindow¡£ func(); //¢Úͨ¹ý¶ÔÏó.·½·¨µ÷Óõģ¬thisÖ¸ÏòÕâ¸ö¶ÔÏó obj.func();//ÏÁÒå¶ÔÏó window.onclick=function(){ document.getElementById("div1").onclick=function(){ func();//×îÖÕ»¹ÊÇʹÓÃ()µ÷Óã¬ËùÒÔÖ¸Ïòwindow } document.getElementById("div1").onclick=func;//¹ãÒå¶ÔÏó£¬Ö¸Ïòdiv } arr=[1,2,3,func,4,5,6]; arr[3](); //¢Üº¯Êý×÷ΪwindowÄÚÖú¯ÊýµÄ»Øµ÷º¯ÊýʹÓã¬thisÖ¸Ïòwindow¡£ setTimeout(func,1000); obj1=new func();

ÏÖÔÚ£¬ÄãÒ»¶¨·ÖÇåÁËthisÖ¸ÏòÁË°É£¬ÏÂÃæÎÒÃÇÀ´¿´Ò»¸ö×ۺϰ¸Àý£º

var obj1={ name:"obj1", arr:[func,1,{name:"obj2",func:func},3,4], } obj1.arr[0]();//×îÖյĵ÷ÓÃÕßÊÇÊý×é¡£this-->obj.arr setTimeout(obj1,arr[0],2000);//obj.arr[0]½ö½öÊÇÈ¡µ½º¯Êý¸³¸øsetTimeout£¬µ«²¢Ã»Óе÷Ó᣺¯ÊýµÄ×îÖÕµ÷ÓÃÕßÊÇsetTimeout¡£Õâ¸öʽ×ÓÏ൱ÓÚsetTimeout(func,2000); obj1.arr[2].func();//×îÖÕµ÷ÓÃÕßÊÇ{name:"obj2",func:func} setTimeout(obj1.arr[2].func,2000);

×îºó£¬ÎÒÃÇÔÙÀ´¿´Ò»µÀÃæÊÔÌ⣺

var fullname = 'John Doe'; var obj = { fullname: 'Colin Ihrig', prop: { fullname: 'Aurelio De Rosa', getFullname: function() { return this.fullname; } } }; console.log(obj.prop.getFullname()); test = obj.prop.getFullname; console.log(test()); // º¯ÊýµÄ×îÖÕµ÷ÓÃÕß test() this-> window obj.func = obj.prop.getFullname; console.log(obj.func()); arr = [obj.prop.getFullname,1,2]; arr.fullname = "JiangHao"; console.log(arr[0

Õâ´Î¾Í·ÖÏíµ½ÕâÁË£¬Ï´ÎÔÙ½éÉÜJSÖÐOOPÖеļ̳з½·¨°É~

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • Ò»ÎÄΪÄãÏêϸ½²½â¶ÔÏóÓ³Éä¿â¡¾AutoMapper¡¿ËùÖ§³Ö³¡¾° - Jeffcky

    Ò»ÎÄΪÄãÏêϸ½²½â¶ÔÏóÓ³Éä¿â¡¾AutoMapper¡¿ËùÖ§³Ö³¡¾° - Jeffcky

    2017-10-08 12:03

  • ¡¾java¡¿¹ØÓÚjavaÀàºÍ¶ÔÏó£¬ÄãÏëÖªµÀµÄÔÚÕâÀ - ÍâÆŵÄÅíºþÍå

    ¡¾java¡¿¹ØÓÚjavaÀàºÍ¶ÔÏó£¬ÄãÏëÖªµÀµÄÔÚÕâÀ - ÍâÆŵÄÅíºþÍå

    2017-09-17 14:05

  • thisµÄÓ÷¨ ¨C JavaScriptÉîÈëdz³ö£¨¶þ£© - OkayChen

    thisµÄÓ÷¨ ¨C JavaScriptÉîÈëdz³ö£¨¶þ£© - OkayChen

    2017-09-15 12:00

  • JavaScript: ʹÓà atan2 À´»æÖÆ ¼ýÍ· ºÍ ÇúÏß - ¾È»ð¶Ó³¤

    JavaScript: ʹÓà atan2 À´»æÖÆ ¼ýÍ· ºÍ ÇúÏß - ¾È»ð¶Ó³¤

    2017-09-14 08:04

ÍøÓѵãÆÀ
Ø