2 ms·
Except they're methods so you have to write (someCondition ? foo.show : foo.hide)(); except the language does not auto-bind so you have to write (som
by masklinn 12y ago
Except they're methods so you have to write
(someCondition ? foo.show : foo.hide)();
except the language does not auto-bind so you have to write
(someCondition ? foo.show : foo.hide).call(foo);
or maybe
(someCondition ? foo.show.bind(foo) : foo.hide.bind(foo))();
- chriswarbo 12y agoOr: foo[someCondition? 'show' : 'hide'](); Although looking up functions using raw strings is less than elegant. I'd be tempted to abstract the pattern using a function, but at that point I'd be doing functional programming anyway and wouldn't be using methods ;)