forked from locutusjs/locutus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall_user_method_array.js
More file actions
27 lines (24 loc) · 1012 Bytes
/
Copy pathcall_user_method_array.js
File metadata and controls
27 lines (24 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function call_user_method_array(method, obj, params) {
// http://kevin.vanzonneveld.net
// + original by: Brett Zamir (http://brett-zamir.me)
// + input by: dnukem
// + improved by: Brett Zamir (http://brett-zamir.me)
// - depends on: Exception
// % note 1: Deprecated in PHP
// * example 1: call_user_method_array('alert', this.window, ['Hello!']);
// * returns 1: 'Hello!'
// * example 1: call_user_method_array([this.window, 'alert'], ['Hello!']);
// * returns 1: 'Hello!'
var func, object = obj, methodName = method;
if (method && typeof method === 'object' && method.length) {
params = obj;
object = method[0];
object = typeof object === 'string' ? this.window[object] : object;
methodName = method[1];
}
func = object[methodName];
if (typeof func !== 'function') {
throw new this.Exception(func + ' is not a valid method');
}
return func.apply(object, params);
}