私はこの奇妙さに困惑しました。
この配列があるとしましょう:
var array = [{
something: 'special'
}, 'and', 'a', 'bunch', 'of', 'parameters'];
オブジェクトが存在し、パラメーターが残りの部分である関数を呼び出す関数apply
のメソッドはありますか?apply
this
{something: 'special'}
array
言い換えれば、私はこれを行うことができますか
var tester = function() {
console.log('this,', this);
console.log('args,', arguments);
};
tester.apply.apply(tester, array);
そして、出力は次のようになると思いますか?
> this, {"something": "special"}
> args, {"0": "and", "1": "a", "2": "bunch", "3": "of", "4": "parameters"}
私はそれを試してみました。
TypeError: Function.prototype.apply: Arguments list has wrong type
しかし、なぜ?これはうまくいくようです。