Home > front end >  How to call method from another object in object?
How to call method from another object in object?

Time:12-09

It is pretty easy when I use it like that

const Object = {
property: propertyFromAnotherObject.method
}

but I want to have this method with my own one

myOwnMethod: () => {
            localStorage.setItem('Storage', null);
}

my attemps to connect end up with fail.

     MyOwnProperty: () => {
            localStorage.setItem('Storage', null);
propertyFromAnotherObject.method         },

CodePudding user response:

use the parenthesis in propertyFromAnotherObject method

  MyOwnProperty: () => {
            localStorage.setItem('Storage', null);
            propertyFromAnotherObject.method()     
   },

CodePudding user response:

to call an object,simply append the method to an object reference with an interventing '. ' (period), and provide any arguments to the method within enclosing parentheses. If the method does not require any arguments, just use empty parentheses.

  • Related