call appply bind

The solution for “call appply bind” can be found here. The following code will assist you in solving the problem.

function foo(arg1, arg2){console.log(`I am ${this.bar}. I am ${arg1}. I am ${arg2}`)};
foo(); // I am undefined. I am undefined. I am undefined

bindFoo = foo.bind({bar: ‘bar’}, ‘argument1’, ‘argument2’); // bind but call later
bindFoo(); // I am bar. I am argument1. I am argument2

foo.call({bar: ‘bar’}, ‘argument1’, ‘argument2’); // call immediately, args passed one by one
// I am bar. I am argument1. I am argument2

foo.apply({bar: ‘bar’}, [‘argument1’, ‘argument2’]); // call immediately, args passed as an array
// I am bar. I am argument1. I am argument2

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in