“To jest JavaScript” Kod odpowiedzi

To jest 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

To JS

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

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

};

user.sayHi(); // John
shahul

to słowo kluczowe w 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);
Abhishek

to słowo kluczowe w Javscript

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

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

To jest 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"*/
Javasper

JavaScript To słowo kluczowe

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

Odpowiedzi podobne do “To jest JavaScript”

Pytania podobne do “To jest JavaScript”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu