Consider having an object named profile
which consists of properties name
and a method called getName
(implemented as an arrow function).
profile = {
name: 'abcd',
getName: () => {
console.log(this.name);
}
}
I am interested in how to execute the getName
method while preserving it as an arrow function, without converting it into a regular function.
Is there a way to achieve the output abcd
by calling getName()
, possibly utilizing expressions within getName
?
Could the use of call()
or bind()
be beneficial in this context? If so, in what manner?
PLEASE MAINTAIN THE ARROW FUNCTION AND AVOID REGULAR FUNCTION CONVERSION
-- MODIFIED --
I am simply intrigued by how arrow functions can be employed within objects to yield outcomes similar to those produced by traditional functions.
This inquiry arose during an interview discussion.