I have defined several methods now and receive a parameter. When accessing a method in this object, how do I access it through a variable?
import moment from 'moment'
let customFun = {
blockRenderFun: {
A: function (value) {
return 'a' + value
},
B: function (value) {
return 'b' + value
},
C: function (value) {
return moment(value).format('YYYY-MM-DD hh:mm:ss')
}
}
}
export default customFun
import customFun from '~/function-modules.js'
let renderSourceArray = ['A','B','C']
let value = 123456
...
customFun.blockRenderFun[renderSourceArray[2]](value) // 此种写法正确,问题关闭
It is known that the properties and methods of the access object can be accessed through "." or "['']"
return a + value
Where did you define a and declare it?
Is this possible without reporting an error?