【发布时间】:2018-04-27 15:12:38
【问题描述】:
我有一个对象数组,是否可以在键值中传递函数?
这是我尝试过但没有成功的方法:(
const myArray = [
{
buttonSelector: '.edit_button',
buttonFunc: '() => console.log('test'),
}
]
运行函数:
myArray.forEach(element => {
element.buttonFunc
}) // should console.log('test')
【问题讨论】:
-
只是不要在函数周围使用单引号?
-
element.buttonFunc()当然去掉单引号 -
不仅可能而且非常普遍。
-
你有一个错字;
buttonFunc:...
标签: javascript