Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript arrow functions to create methods inside objects

let person = {
    name: 'Jack',
    age: 25,
    sayName: () => {

        // this refers to the global .....
        //
        console.log(this.age);
    }
}

person.sayName(); // undefined
Comment

how to make arrow functions as object methods

var chopper = {
    owner: 'Zed',
    getOwner: function() {
        return this.owner;
    }
};

// or

var chopper = {
    owner: 'Zed',
    getOwner() {
        return this.owner;
    }
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: access an object js 
Javascript :: angular material button color 
Javascript :: req.params 
Javascript :: close jquery 
Javascript :: how to dynamically populate pdf with pdfmake node 
Javascript :: axios get array of urls 
Javascript :: useEffect react dependency 
Javascript :: pub js npm 
Javascript :: array delete 
Javascript :: mobile nav react npm 
Javascript :: react 18 double render 
Javascript :: Enqueuing JavaScript in WordPress 
Javascript :: find second largest number in array javascript 
Javascript :: Real image width with JavaScript 
Javascript :: how to add multiple event listener in javascript 
Javascript :: if without else javascript 
Javascript :: javascript Clone Array Using Spread Operator 
Javascript :: javascript save as pdf 
Javascript :: Send Data Using Express With Post 
Javascript :: datepicker date and time 
Javascript :: js get location params 
Javascript :: react router params and render 
Javascript :: asynch action redux 
Javascript :: what is form data in javascript 
Javascript :: initialize firebase app 
Javascript :: javascript remove element from array in foreach 
Javascript :: recordrtc 
Javascript :: angular 8 features 
Javascript :: JavaScript querySelector - By class 
Javascript :: jest check if button is disabled 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =