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

use of this keyword in js

The JavaScript this keyword refers to the object it belongs to. 
It has different values depending on where it is used: In a method, 
this refers to the owner object. Alone, this refers to the global 
object.
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

JavaScript this Keyword

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

this keyword in javscript

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

// ⚙️ Output: {name: 'Mike, call: f}
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 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

PREVIOUS NEXT
Code Example
Javascript :: how to find out what a string ends with in javascript 
Javascript :: how to add a property to a class in javascript 
Javascript :: solidity payable 
Javascript :: leaflet js 
Javascript :: nested json array 
Javascript :: interval manage for javascript 
Javascript :: arrow function example 
Javascript :: remove duplicates strig javascript 
Javascript :: js push multiple arguments 
Javascript :: jqvmap 
Javascript :: nodejs: express: package for Router 
Javascript :: sort array 
Javascript :: javascript dom methods 
Javascript :: react native modal 
Javascript :: json into array 
Javascript :: Javascript "For..in Loop" Syntax 
Javascript :: d3 js 
Javascript :: TypeError: Converting circular structure to JSON 
Javascript :: react using object as prop 
Javascript :: samoglasnici-vowels 
Javascript :: post nodejs 
Javascript :: bot react message with custom emoji 
Javascript :: how to pass functions as a props in react js 
Javascript :: props history 
Javascript :: props 
Javascript :: drag n drop file upload react 
Javascript :: nginx location regex * 
Javascript :: Sort Date string in javascript 
Javascript :: reactjs events list 
Javascript :: javascript Prevent Object MutationPassed 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =