---
layout: page
title: "JavaScript func_num_args function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/func_num_args:407
- /functions/view/func_num_args
- /functions/view/407
- /functions/func_num_args:407
- /functions/407
---
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's func_num_args

{% codeblock funchand/func_num_args.js lang:js https://raw.github.com/kvz/phpjs/master/functions/funchand/func_num_args.js raw on github %}
function func_num_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_num_args();}
  // *     example 1: tmp_a('a', 'b');
  // *     returns 1: 2
  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 arguments.callee.caller.arguments.length;
}
{% endcodeblock %}

 - [view on github](https://github.com/kvz/phpjs/blob/master/functions/funchand/func_num_args.js)
 - [edit on github](https://github.com/kvz/phpjs/edit/master/functions/funchand/func_num_args.js)

### Example 1
This code
{% codeblock lang:js example %}
function tmp_a () {return func_num_args();}
tmp_a('a', 'b');
{% endcodeblock %}

Should return
{% codeblock lang:js returns %}
2
{% endcodeblock %}


### Other PHP functions in the funchand extension
{% render_partial _includes/custom/funchand.html %}
