Schemeãã¤ããã(22) - JavaScriptã®ã¡ã¢
JavaScriptã§Schemeãä½ãçºã«å¿
è¦ãªãã¨ãã¡ã¢ã£ã¨ãã
åå¥è§£æ
tokenize = function(src) { return src.match(/\(|\)|'|[^\s()']+/g); }; // tokenize("(hello Javascript and Scheme world !!)") // => #(( hello Javascript and Scheme world !! ))
é åã«å解åºæ¥ããã¹ããã
ã»ãã»ãã
/\"(?:[^"])*\"/
äºéå¼ç¨ç¬¦ã®æ£è¦è¡¨ç¾ã£ã½ããã(?: )ãä½ãã£ã¦ãã®ããã¼ãããããã¨ã¹ã±ã¼ãå
¥ããã¨æ´ã«å¤§å¤ããã ã»ã»ã»ã
eval
<div onclick="eval(this.firstChild.nodeValue)">alert("hello")</div>
ã¿ã°ã®ä¸ãevalã便å©ã
apply
ç¡ãã¨æ»ããã
var scm = new Scheme(); function len() { return arguments.length } alert(len.apply(this, [1, 2, 3, 4])); // => 4
é¢æ°.apply(ç°å¢, å¼æ°ã®é å)
JavaScriptã«ã¯ã¯ãã¼ã¸ã£ãããã
thisã®é¨åã§éã¶ã¨æ空ãè¶ããããããç¥ããªãã
å
- é£æ³é åã¯Objectå
- é åã¯Arrayå
- null,undefinedã¯Objectãç¶æ¿ãã¦ããªããã
æ¬å¼§ã£ã¦ä¾¿å©ã
ã³ãã³ã§åºåã£ã¦è¤æ°å¼ãæ¸ããã
(alert("hello"), alert("world"))
æ§æã¯ã¨ã©ã¼ã«ãªãã®ã§ãç¡åé¢æ°ã§å²ãã
åè
- å Lisp
- ãªã³ã¯åãã¦ããã©ãわーい \(^o^)/ Scheme もどきを JS で書いたよー! - IT戦記ã®ã½ã¼ã¹ã
- JavaScript の配列と連想配列の違い - IT戦記
- 6ã®ä¾ãå ¨ã¦ã