“это JS” Ответ

Это 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
  }
};
Shirshak kandel

это JS

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

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

};

user.sayHi(); // John
shahul

этот 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)
enochanoak

JavaScript Это ключевое слово

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

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

person.greet();
SAMER SAEID

JavaScript Это ключевое слово

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

это 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.
Oleksandr Shevchuk

Ответы похожие на “это JS”

Вопросы похожие на “это JS”

Больше похожих ответов на “это JS” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования