1
- import { deprecate } from '@ember/debug' ;
2
-
3
1
/**
4
2
Checks to see if the `methodName` exists on the `obj`.
5
3
@@ -25,52 +23,3 @@ export function canInvoke(obj: any | null | undefined, methodName: string): obj
25
23
/**
26
24
@module @ember /utils
27
25
*/
28
-
29
- /**
30
- Checks to see if the `methodName` exists on the `obj`,
31
- and if it does, invokes it with the arguments passed.
32
-
33
- ```javascript
34
- import { tryInvoke } from '@ember/utils';
35
-
36
- let d = new Date('03/15/2013');
37
-
38
- tryInvoke(d, 'getTime'); // 1363320000000
39
- tryInvoke(d, 'setFullYear', [2014]); // 1394856000000
40
- tryInvoke(d, 'noSuchMethod', [2014]); // undefined
41
- ```
42
-
43
- @method tryInvoke
44
- @for @ember /utils
45
- @static
46
- @param {Object } obj The object to check for the method
47
- @param {String } methodName The method name to check for
48
- @param {Array } [args] The arguments to pass to the method
49
- @return {* } the return value of the invoked method or undefined if it cannot be invoked
50
- @public
51
- @deprecated Use Javascript's optional chaining instead.
52
- */
53
- export function tryInvoke (
54
- obj : any | undefined | null ,
55
- methodName : string ,
56
- args : Array < any | undefined | null >
57
- ) {
58
- deprecate (
59
- `Use of tryInvoke is deprecated. Instead, consider using JavaScript's optional chaining.` ,
60
- false ,
61
- {
62
- id : 'ember-utils.try-invoke' ,
63
- until : '4.0.0' ,
64
- for : 'ember-source' ,
65
- since : {
66
- enabled : '3.24.0' ,
67
- } ,
68
- url : 'https://deprecations.emberjs.com/v3.x#toc_ember-utils-try-invoke' ,
69
- }
70
- ) ;
71
-
72
- if ( canInvoke ( obj , methodName ) ) {
73
- let method = obj [ methodName ] ;
74
- return method . apply ( obj , args ) ;
75
- }
76
- }
0 commit comments