phpjs
Version:
56 lines (48 loc) • 1.68 kB
Markdown
layout: page
title: "JavaScript func_get_args function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/func_get_args:406
- /functions/view/func_get_args
- /functions/view/406
- /functions/func_get_args:406
- /functions/406
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's func_get_args
{% codeblock funchand/func_get_args.js lang:js https://raw.github.com/kvz/phpjs/master/functions/funchand/func_get_args.js raw on github %}
function func_get_args () {
// http://kevin.vanzonneveld.net
// + original by: Brett Zamir (http://brett-zamir.me)
// % note 1: May not work in all JS implementations
// * example 1: function tmp_a () {return func_get_args();}
// * example 1: tmp_a('a', 'b');
// * returns 1: ['a', 'b']
if (!arguments.callee.caller) {
try {
throw new Error('Either you are using this in a browser which does not support the "caller" property or you are calling this from a global context');
// return false;
} catch (e) {
return false;
}
}
return Array.prototype.slice.call(arguments.callee.caller.arguments);
}
{% endcodeblock %}
- [view on github](https://github.com/kvz/phpjs/blob/master/functions/funchand/func_get_args.js)
- [edit on github](https://github.com/kvz/phpjs/edit/master/functions/funchand/func_get_args.js)
### Example 1
This code
{% codeblock lang:js example %}
function tmp_a () {return func_get_args();}
tmp_a('a', 'b');
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
['a', 'b']
{% endcodeblock %}
### Other PHP functions in the funchand extension
{% render_partial _includes/custom/funchand.html %}