ãJavaScript Ninjaã®æ¥µæããèªãã
æ¥æ¬èªçãåºãåãã話é¡ã«ãªã£ã¦ããã®ãè¦ã¦ãã¦ãè±èªã ãã©è²·ããããªã¼ã¨æã£ã¦ããã翻訳ããã¦çºå£²ãããã®ã§è²·ãã¾ããã
ããªã話é¡ã«ãªãããªã¨æã£ã¦ããããæå¤ã¨ããã§ããªããã§ãèªãã§è¦ãã¨ãã£ã±ãé¢ç½ãã£ãã®ã§ç´¹ä»ãã¾ãã
ã¨ããããjQueryä½è
ã®John Regigã«ããæ¬ã¨ãããã¨ã§èªããããªãï¼
å
¥éæ¸ã§ã¯ãªããã®ã®ãæåã¯ããªãç°¡åãªå
容ããå§ã¾ã£ã¦ãasserté¢æ°ãä½ã£ã¦ãããå®éã«ä½¿ããªããåä½ã説æãã¦ããæµãã«ãªã£ã¦ãã¾ãã
åºæ¬çã«ã¯ã³ã¼ãã示ãã¦ããã«ã¤ãã¦ã®èª¬æããã¦ããã¹ã¿ã¤ã«ã«ãªã£ã¦ãã¦ãã³ã¼ãã«ãã³ã¡ã³ããä¸å¯§ã«ä»ãããã¦ãã¦ããããããã§ãã
ã¾ããä½ãå®è£
ã示ãã¨ãã«ã使ãå´ã®ã³ã¼ãããè¦ãã¦ããã®å®è£
ãå¾ã§ç¤ºãã®ãèå³ãããããã¦ããã§ãã
é¢æ°
- æåãé¢æ°ã«ã¤ãã¦ã®èª¬æã«ãªã£ã¦ãã¦ãã³ã³ã¹ãã©ã¯ã¿ã«ã¤ãã¦ã®èª¬æãapply, callãç¡åé¢æ°ã®ä½¿ãæ¹ããããããã£ã使ã£ãã¡ã¢åãargumentsã®ä½¿ãæ¹ãªã©ãªã©è²ã
ãªä½¿ãæ¹ãç¥ããã¨ãåºæ¥ã¾ãã
- å人çã«ã¯ãfunction.lengthã¨aruguments.lengthã使ã£ããªã¼ãã¼ãã¼ãã®å®è£ ããªãã»ã©ãªãã¨æãé¢ç½ãã£ãã§ãã
- ç¹ã«åãå¼æ°ãæã¤ã¡ã½ãããæ¢ç´¢ãã¦ããã³ã¼ããã
ã¯ãã¼ã¸ã£
- ã¯ãã¼ã¸ã£ã«ã¤ãã¦ãç¥ããªã人åãã«ä¸å¯§ã«èª¬æããã¦ãã¦ããããããã§ãã
- ã¯ãã¼ã¸ã£ã使ããã¨ã«ãã£ã¦ã¤ãã³ãé§åãªã³ã¼ããæ¸ãããããªã£ã¦ãããã¨ããbindãcurryåãã¡ã¢åãªã©ãã®è¾ºãããå°ããã¤èãã¦èªãã³ã¼ããå¢ãã¦ãã¾ãã
- å³æé¢æ°ã使ã£ã¦é·ãããããã£ãçç¥ããã®ã¯ãããªã«æèãã¦ããªãã£ãã®ã§ããã確ãã«ä¾¿å©ã ãªã¨æãã¾ããã
(function(v) { v.value ... })(element.someLongAttribute);
ãããã¿ã¤ã
- ãããä¸å¯§ã«èª¬æããã¦ãã¦ããããããã§ãããobj.constructor.prototypeã¨ãªã£ã¦ããããprototypeã«è¿½å ããã¡ã½ãããæ¢ããã¨ãããã©ããã¯ã¢ã¬ãï¼ã¨æãã¾ãããobj.__proto_ã¿ãããªå
é¨ããããã£ã«prototypeãã»ããããã¦ãããããæ¢ããããã«ãªã£ã¦ããã ã¨æã£ã¦ããã®ã§ã
- 確èªãã¦ã¿ãï¼å®è£ ã«ããã®ããããã¾ããã..ï¼
- Ninja.prototype = Person.prototypeã§ãªãã¦ãNinja.prototype = new Person()ã«ããæ¹ãçç±ãªããããã£ããæ¸ããã¦ããã®ããããªã¨æãã¾ããã
- ã¯ã©ã¹ã½ãã®ãã¤ããsubClassé¢æ°ã®å®è£
ã¯ã ãã¶æå¼·ãæãã§ãããå®è£
ã¯1ãã¼ã¸åãããã§ããããã®å®è£
ã«ã¤ãã¦ã®èª¬æã¯5ãã¼ã¸ããããã£ã¦ããªãåå¼·ã«ãªãã¾ãã
- å ¨é¨ç解åºæ¥ã¦ãã¾ããã...
æ£è¦è¡¨ç¾
- å¿ã³è¢ã«å ¥ãã¦ããã¹ãæ¦å¨ã¨ãã¦ç´¹ä»ããã¦ãã¦ãhtmlæååã®æ£è¦è¡¨ç¾ã«ããæä½ãä¸å¿ã«æ¯è¼çåºæ¬çãªä½¿ãæ¹ãç´¹ä»ããã¦ãã¾ãã//ãªãã©ã«ã§ã¯ãªãã¦ãnew Regex()ã使ãã¹ãå ´é¢ãªã©ãããé ã®ä½æã«ãªã£ã¦èªãã§ãã¦é¢ç½ãã£ãã§ãã
ã¹ã¬ããã¨ã¿ã¤ã
- ã¡ã¤ã³ã®å¦çã¨ããã¦ã¹ã¤ãã³ããsetTimeoutãsetIntervalãèµ·ãã£ãæã«ãé 延ããªããã©ã®ããã«å®è¡ããã¦ãããã®å³ãæåã«ç´¹ä»ãããã®ã§ããããããã¨ã¦ãããããããã§ãã
- setTimeoutãç¹°ãè¿ãå®è¡ããæã¨setIntervalã¨ã®éãã«ã¤ãã¦ãæ¸ããã¦ãã¦ãªãã»ã©ãªãã¨æãã¾ããã
- ã¾ãéãå¦çã§UIãæ¢ããªãããã«ãsetTimeout使ããªã©ãã·ã³ã°ã«ã¹ã¬ãããªãã§ã¯æ³¨æç¹ã«ã¤ãã¦ããã£ããæ¸ããã¦ãã¾ãã
- ã¨ã¦ãããç« ã ã¨æãã¾ãã
å®è¡æã®ã³ã¼ãã®è©ä¾¡
- ããã§ã¯evalã«ã¤ãã¦ããFunction.toString()ã使ã£ãå¼æ°åã®åãæ¹ãªã©ãç´¹ä»ããã¦ãã¾ãã
- ã¾ããã³ãã¬ã¼ãã¨ã³ã¸ã³ã®å®è£
ãªã©ã§ä½¿ããã¦ãwithã«ã¤ãã¦ãä¸ç« 使ã£ã¦åãä¸ãããã¦ãããæ¹ãã¦ãã®åä½ã«ã¤ãã¦ç¥ããã¨ãåºæ¥ã¾ãã
- å®éã¯ä½¿ããªãã¨æãã¾ãã...
ã¯ãã¹ãã©ã¦ã¶
- ããããã¯jQueryã§ã®éçºã®çµé¨ããã¨ã«ãã¯ãã¹ãã©ã¦ã¶å¯¾å¿ã«ã¤ãã¦ããªã詳ããæ¸ããã¦ãã¦ãç´¹ä»ãããã³ã¼ãã®å
容ãé«åº¦ã«ãªã£ã¦ãã¾ãã
- ç解åºæ¥ãªãã£ãã¨ãããçµæ§ããã¾ãã
- ãããè¦ããjQueryã«è¶³ãåãã¦å¯ããªããªã¨æãã¾ããã
- ã©ã®ãã©ã¦ã¶ã§ãåãããã«ããã ãã§ãªããããã©ã¼ãã³ã¹ãæ§ã ãªãã¨ãèæ ®ãã¦ãããã¨ãããããã¨ã¦ãèªã¿å¿ããããã¾ããã
ã¡ãªã¿ã«æ´æ¸ã®æ¹ã¯ããããã¯ãµã ã©ã¤ã§ã¯ï¼ãã¨ãã表ç´ã§ããããæ¥æ¬èªçã§ã¯ã¡ããã¨å¿è ãªãã£ãããæãã«ãªã£ã¦ã¾ã