phpjs
Version:
60 lines (49 loc) • 1.93 kB
Markdown
layout: page
title: "JavaScript function_exists function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/function_exists:408
- /functions/view/function_exists
- /functions/view/408
- /functions/function_exists:408
- /functions/408
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's function_exists
{% codeblock funchand/function_exists.js lang:js https://raw.github.com/kvz/phpjs/master/functions/funchand/function_exists.js raw on github %}
function function_exists (func_name) {
// From: http://phpjs.org/functions
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Steve Clay
// + improved by: Legaev Andrey
// + improved by: Brett Zamir (http://brett-zamir.me)
// * example 1: function_exists('isFinite');
// * returns 1: true
if (typeof func_name === 'string') {
func_name = this.window[func_name];
}
return typeof func_name === 'function';
}
{% endcodeblock %}
- [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/funchand/function_exists.js)
Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are
the closest match to this hashtable-like data structure.
Please also note that php.js offers community built functions and goes by the
[McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online
functions that are far from perfect, in the hopes to spark better contributions.
Do you have one? Then please just:
- [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/funchand/function_exists.js)
### Example 1
This code
{% codeblock lang:js example %}
function_exists('isFinite');
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
true
{% endcodeblock %}
### Other PHP functions in the funchand extension
{% render_partial _includes/custom/funchand.html %}