parameter passing - Javascript: argument unpacking in function.prototype.bind()? -
this question has answer here:
the closest i've seen this, doesn't me since need bind parameters later use setinterval.
more specifically:
[in] var d = function(l, m) { console.log(l); console.log(m); } [in] d.apply(window, [1,2]) [out] 1 [out] 2 [out-return-value] undefined [in] d.bind(window, [1,2])() [out] [1, 2] [out] undefined [out-return-value] undefined
as can seen, arrays unpacked .apply()
, not .bind()
. there way unpack arguments .bind()
?
.bind
function. call .apply
if want call array of arguments:
var bound = d.bind.apply(d, [window, 1, 2]); // if `this` value known, arguments array, concat: // var bound = d.bind.apply(d, [window].concat(args))
Comments
Post a Comment