0

singleを使用して、javascript の既存の関数に引数を渡そうとしていbind()ます。

var connect = function(index) {
    console.log(this.single);
    ...
}

var connect_fn = connect;
connect_fn.bind({
    single: true
});

$(".box").each(connect_fn);

残念ながら、console.log() this.singleは定義されていません。

4

1 に答える 1

1

bind新しい関数を返します。

connect_fn = connect_fn.bind({
    single: true
});

完全な例:

function test() {
    console.log(this.test);
}

test.bind({test: 'test'})();
于 2013-10-25T21:05:30.163 に答える