Function

tryInvoke (obj, methodName, args) * public deprecated

Module: @ember/utils
import { tryInvoke } from '@ember/utils';
obj
Object
The object to check for the method
methodName
String
The method name to check for
args
Array
The arguments to pass to the method
returns
*
the return value of the invoked method or undefined if it cannot be invoked

Checks to see if the methodName exists on the obj, and if it does, invokes it with the arguments passed.

import { tryInvoke } from '@ember/utils';

let d = new Date('03/15/2013');

tryInvoke(d, 'getTime');              // 1363320000000
tryInvoke(d, 'setFullYear', [2014]);  // 1394856000000
tryInvoke(d, 'noSuchMethod', [2014]); // undefined

© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Futils/tryInvoke