é¢æ°ã®ä»®å¼æ°åãåå¾ããã
prototype.jsãã¤ã³ãã¼ãããã¨è¿½å ããããFunction#argumentNamesãã使ãã¨ããé¢æ°ã®ä»®å¼æ°åä¸è¦§ããåå¾ã§ãã¾ãã
// é¢æ°ã var f = function( mii, tora, shiro ) {} // ä»®å¼æ°ä¸è¦§ãåå¾ var out = document.getElementById( "out" ); out.innerHTML += f.argumentNames().join(",") + "<br/>";
ã©ããã£ã¦åå¾ãã¦ããã ?ã¨æã£ã¦ã³ã¼ããè¦ã¦ã¿ãã¨ãã¡ã½ããã®toString()ã§åå¾ããã½ã¼ã¹ã解æãã¦åãåºãã¦ããããã§ãããªãã»ã©ã¼ã以ä¸ãprototype.jsããæç²ã§ãã
Object.extend(Function.prototype, { argumentNames: function() { var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip"); return names.length == 1 && !names[0] ? [] : names; }, ...
DIã³ã³ããã§ã®ã³ã³ãã¼ãã³ãã®èªåã¤ã³ã¸ã§ã¯ã·ã§ã³ã¨ãã«ä½¿ãããã§ãããã³ã³ã¹ãã©ã¯ã¿ã®ä»®å¼æ°åã«å¯¾å¿ããã³ã³ãã¼ãã³ããç»é²æ¸ã¿ã§ããã°å¼æ°ã¨ãã¦æ¸¡ããã¨ãã