Explorer
Node.js

Write a function `demonstrateThis()` that shows how bind, call, and apply change `this` context.

Problem Statement

Write a function `demonstrateThis()` that shows how bind, call, and apply change `this` context.

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: call() invokes with a specific this and individual args. šŸ’” Hint 2: apply() is like call() but takes args as an array. šŸ’” Hint 3: bind() returns a new function with this permanently bound. āœ… Solution: ```javascript function demonstrateThis() { const obj = { name: "Alice" }; function greet(greeting) { return `${greeting}, ${this.name}`; } return { call: greet.call(obj, "Hello"), apply: greet.apply(obj, ["Hi"]), bind: greet.bind(obj)("Hey") }; } ```

Bind, Call, Apply

Medium
Write a function `demonstrateThis()` that shows how bind, call, and apply change `this` context.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
{"call":"Hello, Alice","apply":"Hi, Alice","bind":"Hey, Alice"}