typeof æ¼ç®å㨠RegExp ãªãã¸ã§ã¯ã
Fx3 ã® MozRepl ã® search ã¡ã½ãããåããªããªã¼ã¨æã£ã¦ãã¦èª¿ã¹ãå
容ã§ãã
ã¡ãªã¿ã«ä»æ§çãªãã®ãå¼ã£å¼µã£ã¦æ¥ã¦ãã¾ãããJSã¯éå¤æ¼¢ãªã®ã§èªå·±è²¬ä»»ã§ãé¡ããã¾ãï¼ã
repl.search() ã®å®è£
function search(criteria, context) { context = context || this._workContext;var matcher; if (typeof criteria == "function") { matcher = criteria; } else { matcher = function (name) { return name == criteria; }; } for (var name in context) { if (matcher(name)) { this.print(name); } } }
ã£ã¦ãªå ·åã§ãrepl.search(regex, obj)ããrepl.search(func, obj)ã¿ããã«ä½¿ããããºã
typeof regex
ã§ãçµè«ããè¨ãã¨Fx3ã§ã¯ã
typeof (/^foo/)
㯠"object" ã¨è¿ã£ã¦ãããå¾ã£ã¦æåã® if-else 㧠else å¥ãå®è¡ãããã¨è¨ããªãã
typeof regexã®æå
11.4.3 typeof 演算子 (The typeof Operator) ã«ããã°ã
Object (native and doesn't implement [[Call]]) "object" Object (native and implements [[Call]]) "function" Object (host) Implementation-dependent
ã¨ãããããã§è¨ã[[Call]]ã¨ã¯ã8.6.2 内部プロパティとメソッド ã«ããå é¨ããããã£ã®äºã§ã
ãããã㣠ãã©ã¡ã¼ã¿ 説æ [[Call]] å¼åºå´ãæä¾ããå¼æ°å¤ã®ãªã¹ã ãªãã¸ã§ã¯ãã«é¢é£ããã³ã¼ããå®è¡ããã é¢æ°å¼åºã®å¼ (expression) ãçµç±ãã¦å¼åºãããã ãã®å é¨ã¡ã½ãããå®è£ ãããªãã¸ã§ã¯ãã¯é¢æ° (function) ã¨å¼ã°ããã
ã¾ã [[Call]] å é¨ããããã£ãæã¦ã°é¢æ°å¼ã³åºãå¯è½ã ãã¨è¨ãäºã§è¯ãããã
ã¨ããã§ã
å¿ é ã®å é¨ããããã£ã«å ãã¦ãåãã¡ã³ã¯ã·ã§ã³å®ä½ã¯ [[Call]] ããããã£ã [[Construct]] ããããã£ã [[Scope]] ãããã㣠(8.6.2 åã³ 13.2 ãåç §) ãæã¤ã[[Class]] ããããã£ã®å¤ã¯ "Function" ã§ããã
ã¨ããããã« Function ã¤ã³ã¹ã¿ã³ã¹ã¯ãã¡ããå¼ã³åºãå¯è½ãªã®ã ãã15.10.7 RegExp インスタンスのプロパティ (Properties of RegExp Instances) ã«ã¯ [[Call]] ããããã£ã¯åå¨ããªããã¤ã¾ãå¼ã³åºãå¯è½ã§ã¯ç¡ãã®ã ECMAScript 3rd çã«ã¯æ£ããã¨æãããããå®éã«ã¯ Firefox ã Safari ã§ã¯å¼ã³åºãã模æ§ã
ããã¾ã§ã¾ã¨ããã¨ãRegExpãªãã¸ã§ã¯ãã¯ã
ãæ¬æ¥æ£ããã¨æããã¾ããã§Fx2, Fx3ã§ã®çµæããããã並ã¹ãã¨ã
browser | typeof | call | |||
Fx2 | function | åºæ¥ã | |||
Fx3 | object | åºæ¥ã |
ã¨ãªã£ã¦ãã¦ãã¾ãä½ã¨ãè¨ããªãç¶æ³ã¿ããã
ã¾ã¨ã
id:amachangããã£ã¨è£è¶³ãã¦ããã¾ãã
ããã¯ã¨ãããtypeofã§regexãæå¾
ããå¤æ°ã®ãã§ãã¯ã¯ãã¡ã§ããFxãªã³ãªã¼ã§ãããªãã
typeof regex == "function" || regex.__proto__ == RegExp.prototype
ãªã©ã§å¤å¥ããã¨è¯ãããã
ãããã
追è¨
å¤å®ã¯æ®éã«instanceof RegExpã§ããã¡ãããkã§ãã(thanks id:ku0522)