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 keyword in javascript

// this keyword

// This keyword belongs to the object it belongs to
// (1).Alone, this refers to the global object.
// (2).In a regular function,this refers to the global object.
// (3).In a method, this refers to the owner object.

// 1
console.log(this);

// 2
function abc() {
  console.log(this);
}
abc();

// 3
const obj = {
  name: "Abhishek",
  no: 1,
  sum: function (a, b) {
    console.log("hello sum", a + b);
    console.log("this:::", this);
    console.log("this name:::", this.name);
  },
};

obj.sum(4, 3);
Comment

this js

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

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

};

user.sayHi(); // John
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

this keyword in javscript

const user = {
    name: 'Mike';
    call() {
        console.log(this);
    }
}
user.call();

// ⚙️ Output: {name: 'Mike, call: f}
Comment

this keyword in javascript

// In JavaScript, the this keyword refers to an object.

const person = {
  firstName: "John",
  lastName : "Doe",
  id       : 5566,
  fullName : function() {
    return this.firstName + " " + this.lastName;
  }
};
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 :: javascript get params from query string json object 
Javascript :: function that duplicates data in array js 
Javascript :: how to add new line in jsx 
Javascript :: react laravel 
Javascript :: mongoose get id after save 
Javascript :: antd react 
Javascript :: javaScript Option to deactivate all bs.tooltip on document 
Javascript :: add getter to object javascript 
Javascript :: javascript Example 1: Regular Expressions 
Javascript :: javascript while loop 
Javascript :: forever.js 
Javascript :: MONGOOSE update on by body 
Javascript :: submit form react js 
Javascript :: js object without prototype 
Javascript :: filter an array 
Javascript :: password validation in angular 
Javascript :: string object js 
Javascript :: javascript check if consecutive array 
Javascript :: javascript how to pass more than one selector in querySelectorall 
Javascript :: hosting react with pm2 
Javascript :: react native dynamically update flatlist data 
Javascript :: Using axios send a GET request to the address: 
Javascript :: event.propagation not working 
Javascript :: reverse a string javascript 
Javascript :: in vs of javascript 
Javascript :: react input cursor jump end 
Javascript :: a go to id js 
Javascript :: password reset passport-local mongoose 
Javascript :: react loop through array 
Javascript :: vue compare two dates 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =