forked from locutusjs/locutus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Porting forward_static_call functions and fix to call_user_func().
- Loading branch information
Showing
5 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function forward_static_call(cb, parameters) { | ||
// http://kevin.vanzonneveld.net | ||
// + original by: Brett Zamir (http://brett-zamir.me) | ||
// % note 1: No real relevance to late static binding here; might also use call_user_func() | ||
// * example 1: forward_static_call('isNaN', 'a'); | ||
// * returns 1: true | ||
|
||
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, Array.prototype.slice.call(arguments, 1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function forward_static_call_array(cb, parameters) { | ||
// http://kevin.vanzonneveld.net | ||
// + 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); | ||
} |