Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

this in javascript

//this refer to global object or window object
//but when we call this inside method of object it refers to current object
console.log(this===window)//true
let user = {
  name: "Shirshak",
  age: 25,

  sayHi() {
    // "this" is the "current object"
    console.log(this.name); //print shirshak
  }
};
Comment

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
    });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: Javascript Scrape content from a website source code 
Javascript :: button as a link react 
Javascript :: convert html to javascript 
Javascript :: string charat 
Javascript :: blur javascript 
Javascript :: javascript extract array from object 
Javascript :: setimmediate node example 
Javascript :: clear cache javascript 
Javascript :: material-ui add icon to switch when on 
Javascript :: object length 
Javascript :: first element of array js 
Javascript :: getDownload url in firebase 
Javascript :: how to write to a file with javascript without nodejs 
Javascript :: firebase realtime database increment value 
Javascript :: how do you pass props between components 
Javascript :: how to check empty string array in javascript 
Javascript :: js arrow function vs function 
Javascript :: api integration for web pages in next js 
Javascript :: Adding an item to an array 
Javascript :: javascript code checker 
Javascript :: what is console working for in js 
Javascript :: discord role giver 
Javascript :: how to sort one element in property javascript 
Javascript :: javascript double exclamation mark 
Javascript :: browser support fetch api 
Javascript :: javascript sucks 
Javascript :: findOne 
Javascript :: define conastant js 
Javascript :: JSON to Ruby Hash Parser 
Javascript :: javaScript Age in Dog years //write a function that takes your age and returns it to you in dog years - they say that 1 human year is equal to seven dog years function dog Years() javaScript 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =