I have an Ember object that has several actions :
MyObject = Ember.Object.extend {
action1: ->
console.log "do 1"
action2: ->
console.log "do 2"
}
I'd like to call one of these action depending on some condition. The easy way is
to check for this condition and call the needed condition using if
or switch-case
. But, I need something more scalable like a hash of method inside my object and invoke the needed method by just sending their name like object.exec('action1')
.
Does ember object has already this feature ?
obj.get('action1').apply(obj, yourarguments)
? – louiscoquioapply
takes two arguments: the value forthis
, and an array of arguments. If you wants to pass arguments without put them in an array, you should usecall
which takes the value forthis
as the first argument, and all others arguments are directly passed to the method. I suggest you to read the first answer: goo.gl/5z6yx – louiscoquio