2011-08-27
Function::arguments
tips, javascript | |
argumentsは引数リストだと思っていたら、実はオブジェクトらしい。
arrayにそのまま渡したい時に困るのだが、変換できる。
Array.prototype.slice.call(arguments)
https://developer.mozilla.org/en/JavaScript/Reference/functions_and_function_scope/arguments
Function::apply and call
tips, javascript | |
JSのapplyってずっとよくわかってなかったので調べてみた。
schemeの(apply <func> <list>)と同じようなもんと考えて納得。
"hoge".slice() //=> "hoge" [].slice.apply("hoge") // => ["h", "o", "g", "e"]
Array.prototype.slice.apply("hoge", [3,4]) Array.prototype.slice.call("hoge", 3, 4)
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/function/apply
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/call
コメントを書く
