javascript tutorial 5: call, apply, bind, promises, and more
Page preview (5 pages)
Scroll down 👇
About "javascript tutorial 5: call, apply, bind, promises, and more"
javascript tutorial 5: call, apply, bind, promises, and more 1. call, apply, and bind these three methods are used to explicitly set the value of this when calling a function. they allow you to control the context in which a function is executed. 1.1 call() the call() method calls a function with a given this value and arguments provided individually. syntax: function.call(thisarg, arg1, arg2, ...) example: const person = { name: 'alice', greet: function(greeting) { console.log(`${greeting}, my name is ${this.name}`); } }; const anotherperson = { name: 'bob' }; // using call to invoke greet with 'this' pointing to anotherperson person.greet.call(anotherperson, 'hello'); // output: hello, my name is bob 1.2 apply() the apply() method is similar to call(), but it …
This file contains 20 pages in PPTX format (265.3 KB). To download "javascript tutorial 5: call, apply, bind, promises, and more", click the Telegram button on the left.