Use PHP functions in JavaScript

JavaScript forward_static_call_array

!No description available for forward_static_call_array. @php.js developers: Please update the function summary text file.

1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
2526
27
28
29
30
function forward_static_call_array (cb, parameters) {
    // !No description available for forward_static_call_array. @php.js developers: Please update the function summary text file.
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/forward_static_call_array    // +   original by: Brett Zamir (http://brett-zamir.me)
    // %          note 1: No real relevance to late static binding here; might also use call_user_func_array()
    // *     example 1: forward_static_call_array('isNaN', ['a']);
    // *     returns 1: true
    // *     example 2: forward_static_call_array('isNaN', [1]);    // *     returns 2: false
    var func;
 
    if (typeof cb == 'string') {
        if (typeof this[cb] == 'function') {            func = this[cb];
        } else {
            func = (new Function(null, 'return ' + cb))();
        }
    }    else if (Object.prototype.toString.call(cb) === '[object Array]') {
        func = eval(cb[0] + "['" + cb[1] + "']");
    }
 
    if (typeof func != 'function') {        throw new Error(func + ' is not a valid function');
    }
 
    return func.apply(null, parameters);
}
external links: original PHP docs | raw js source

Examples

» Example 1

Running

1
forward_static_call_array('isNaN', ['a']);

Should return

1
true

» Example 2

Running

1
forward_static_call_array('isNaN', [1]);

Should return

1
false

Dependencies

No dependencies, you can use this function standalone.

Open syntax issues

php.js uses JsLint to help us keep our code consistent and prevent some common bugs.

Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.


Authors

Thanks to the following developers, you get to have forward_static_call_array goodness in JavaScript.

Comments

Add Comment
Use:
[CODE]
your_stuff('here');
[/CODE]
for proper code formatting
By submitting code here you are allowing us to use it in php.js hence dual licensing it under the MIT and GPL licenses

No comments yet. Be the first!


Contribute a New function

More functions

In this category

call_user_func
call_user_func_array
create_function
forward_static_call
» forward_static_call_array
func_get_arg
func_get_args
func_num_args
function_exists
get_defined_functions
register_shutdown_function

Support us

spread the word:


Use any PHP function in JavaScript


These kind folks have already donated: AYHAN BARI*, Nikita Ekshiyan, Nikita Ekshiyan, Petr Pavel, @HalfWinter, Paulo Freitas, Andros Peña Romo, @andorosu, Raimund Szabo, Nitin Gupta, @nikosdion, Anonymous, Anonymous and Shawn Houser.
<your name here>

Click here to lend your support to: phpjs and make a donation at www.pledgie.com !