Stack Overflow Asked by bob saggy on December 22, 2021
Consider
a = {apple: "the value of this is ${value}"}
I want to call on this such that
a = {apple: "the value of this is ${value}"}
console.log(a.apple("16")) => outputs "the value of this is 16"
Anyway to do this in javascript?
Maybe a setter
const a = {
_apple: "the value of this is ",
set apple(value){
this._apple = this._apple + value;
}
};
a.apple = '16';
console.log(a._apple);
Answered by sonEtLumiere on December 22, 2021
do you mean as following:
const a = { apple: (value) => `the value of this is ${value}` }
Answered by tmhao2005 on December 22, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP