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?
do you mean as following:
const a = { apple: (value) => `the value of this is ${value}` }
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.