Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

this is 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

// 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"
Comment

this js

let user = {
  name: "John",
  age: 30,

  sayHi() {
    // "this" is the "current object"
    alert(this.name);
  }

};

user.sayHi(); // John
Comment

JavaScript this Keyword

const person = {
  firstName: "John",
  lastName : "Doe",
  id       : 5566,
  fullName : function() {
    return this.firstName + " " + this.lastName;
  }
};
Comment

this javascript

/*In general, the 'this' references the object of which the function is a property.
In other words, the 'this' references the object that is currently calling the function.
Suppose you have an object called 'counter' that has a method 'next()'.
When you call the 'next()' method, you can access the this object. */

let counter = {
  count: 0,
  next: function () {
    return ++this.count;
  },
};
counter.next(); 
//Inside the next() function, the this references the counter
Code language: JavaScript (javascript)
Comment

javascript this keyword

const refObj = {
    func: function(){
      console.log(this);
    }
  };
Comment

JavaScript this Keyword

const person = {
    name: 'John',
    age: 30,

    // accessing name property by using this.name
    greet: function() { console.log('The name is' + ' ' + this.name); }
};

person.greet();
Comment

This is JavaScript

var Backbone = {};
Backbone.a = "aaa";
Backbone.b = "bbbb";
Backbone.c = "ccccc";
Backbone.t = function()
{
  console.log(this);
}
 function clickMe()
 {

Backbone.t();
/*console.log(this) is Backbone object (remember how "this" is "whoever owns the function"*/
Comment

this javascript

// Im Webbrowser ist das window Objekt das globale Objekt:
console.log(this === window); // true

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

this.b = "MDN";
console.log(window.b);  // "MDN"
console.log(b);         // "MDN"
Comment

this js

document.querySelector("button.w").addEventListener("click", function () {
    this.style.color = "white";
});
// In HTML event handlers, this refers to the HTML element that received the event:
// when clicked color of the element would change to white, 
// document.querySelector("button.w") indentifies the element.
Comment

PREVIOUS NEXT
Code Example
Javascript :: dynamic classes in react 
Javascript :: angular firebase 
Javascript :: object.create() js 
Javascript :: compare two dates in javascript 
Javascript :: how to define width with [styles] in percentage in angular 
Javascript :: javascript stack reverse 
Javascript :: mongoose read 
Javascript :: react proxy error: could not proxy request from localhost:3000 to http localhost:5000 econnreset 
Javascript :: js try..catch works synchronously. 
Javascript :: next auth 
Javascript :: capitalize first letter of a string 
Javascript :: angular pipe paramerte 
Javascript :: first unique character in a string javascript 
Javascript :: why sort is not working in javascript 
Javascript :: linux command to install standard js 
Javascript :: get file extension of path extendscript 
Javascript :: javascript how-do-i-check-whether-a-checkbox-is-checked-in-jquery 
Javascript :: discord js check if message author is admin 
Javascript :: node js arabic number to english number 
Javascript :: javascript diffence between a++ and ++a 
Javascript :: faker js uuid example 
Javascript :: Get Arrays in sequelize 
Javascript :: react call bind apply 
Javascript :: java script add fields dynamically 
Javascript :: try catch 
Javascript :: loop over documents in mongoose 
Javascript :: iterate over array of object javascript and access the properties 
Javascript :: swiper js 
Javascript :: default in javascript 
Javascript :: javascript parseInt() method 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =