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: 1008.1718 // 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 (cb instanceof 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); } |
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.
No comments yet. Be the first!
spread the word:
Use any PHP function in JavaScript
These kind folks have already donated: @HalfWinter, Paulo Freitas, Andros Peña Romo, Nitin Gupta, @nikosdion, Anonymous, Anonymous and Shawn Houser.
<your name here>