Reputation: 45350
I am trying to pass an argument single
into a preexisting function in javascript with bind()
.
var connect = function(index) {
console.log(this.single);
...
}
var connect_fn = connect;
connect_fn.bind({
single: true
});
$(".box").each(connect_fn);
Unfortunately, in the console.log()
this.single
is undefined.
Upvotes: 0
Views: 32
Reputation: 43718
bind
returns a new function.
connect_fn = connect_fn.bind({
single: true
});
Full example:
function test() {
console.log(this.test);
}
test.bind({test: 'test'})();
Upvotes: 1