簡體   English   中英

如何在帶有普通 javascript 的 object 中將值設置為參數?

[英]How do I set a value as a parameter inside an object with plain javascript?

考慮

a = {apple: "the value of this is ${value}"}

我想這樣呼吁

a = {apple: "the value of this is ${value}"}
console.log(a.apple("16")) => outputs "the value of this is 16"

無論如何要在 javascript 中執行此操作?

你的意思是如下:

const a = { apple: (value) => `the value of this is ${value}` }

也許是二傳手

 const a = { _apple: "the value of this is ", set apple(value){ this._apple = this._apple + value; } }; a.apple = '16'; console.log(a._apple);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM