Answers for "this in JavaScript"

10

what is this in javascript

// this = current execution context (window in browser, global in nodejs)
console.log(this) // window object

function foo () {
 console.log(this); // object calling this function
}

foo(); // undefined

o={ foo }
o.foo(); // 'o' object logged
Posted by: Guest on June-21-2021
17

javascript this

// In web browsers, the window object is also the global object:
console.log(this === window); // true

a = 37;
console.log(window.a); // 37

this.b = "MDN";
console.log(window.b)  // "MDN"
console.log(b)         // "MDN"
Posted by: Guest on February-21-2020
1

js this in object

var wF = {
    w : 560,
    h : function() { return (312 - 42) / (560 / this.w) + 42; }
};

alert(wF.h())
Posted by: Guest on August-04-2020
0

javascript this = that

var colours = ['red', 'green', 'blue'];
document.getElementById('element').addEventListener('click', function() {
    // this is a reference to the element clicked on

    var that = this;

    colours.forEach(function() {
        // this is undefined
        // that is a reference to the element clicked on
    });
});
Posted by: Guest on December-16-2020
0

this keyword in javascript

"use strict";
function myFunction() {

    return this;

}
Posted by: Guest on June-26-2021
-1

this in JavaScript

Go to This link :- https://itnext.io/the-this-keyword-in-javascript-demystified-c389c92de26d
Posted by: Guest on August-29-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language