About 567,000 results
Open links in new tab
  1. javascript - How do I pass the this context to a function

    Javascripts .call() and .apply() methods allow you to set the context for a function. var myfunc = function(){ alert(this.name); }; var obj_a = { name: "FOO" }; var obj_b = { name: "BAR!!" }; Now you can call: myfunc.call(obj_a); Which would alert FOO. The other way around, passing obj_b would alert BAR!!.

  2. this - JavaScript | MDN - MDN Web Docs

    Apr 10, 2025 · The this keyword refers to the context where a piece of code, such as a function's body, is supposed to run. Most typically, it is used in object methods, where this refers to the object that the method is attached to, thus allowing the …

  3. Function Context - Learn JavaScript - Free Interactive JavaScript

    Functions defined under an object or a class (another function) will use the context of the object it was created in. However, we can also change the context of a function at runtime, either before or while executing the function.

  4. How to change the context of a function in javascript

    Jun 1, 2015 · You can easily change the context of a function in jquery using the proxy() function. See this question: jquery "this" binding issue on event handler (equivalent of bindAsEventListener in prototype) and the first answer

  5. JavaScript function/method context check - Stack Overflow

    Jun 22, 2013 · I know how to use the methods for changing the context of a function/method call: apply, bind, call. My question is this, is there a way to check if a function/method has already had its context set?

  6. Understanding Context in JavaScriptObject Literals - Kevin …

    Instead of simply returning “this.drink”, we use the JavaScript “.call()” method, which allows you to execute any function in the context of another object. When you do not specify the context in which that function is to be “called”, it executes in the context of the global object.

  7. How to understand the keyword this and context in JavaScript

    Dec 21, 2018 · When you start having functions, you might have different levels of your program and this represents where you are, what object called the function. Let’s have a look at the following example and see how this changes depending on the context: console.log(`The coffee is ${this.strong ? '' : 'not '}strong`) }, } .

  8. Mastering Function Context in JavaScript: - Medium

    Jun 27, 2023 · Understanding the concepts of call, bind, and apply in JavaScript gives you powerful tools to control function context and argument passing. The call method allows for explicit context setting,...

  9. Function context in JavaScript - DEV Community

    Dec 23, 2018 · In this post we will take a look at context inside a JavaScript function, how to assign context to a function with some examples.

  10. Function Context - Learneroo

    Functions in JavaScript run in a specific context, and using the this variable we have access to it. All standard functions in the browser run under the Window context. Functions defined under an object or a class (another function) will use the context of the object it was created in.

  11. Some results have been removed