I talked with @jasnell about this on Monday, so I'm tagging him on this :)
When using util.inspect for functions, the output length value seems to indicates the number of parameters in the inspected function.
Where things break is with functions that have default values. Below is a straight-forward proof
of concept that demonstrates the incorrect behavior. I assume with is related to the addition of the = sign
and commas which may or may not be param separators.
Code
'use strict';
const util = require('util');
function cats(a, b, c = [1, 2, 3], d, e, f) {}
function dogs(a, b, c = {d: '1', e: 2}, f, g) {}
function mice(a = '1,2,3', b='cheese') {}
function unicorns(a, b, c) {}
console.log(util.inspect(cats, { showHidden: true, depth: null }));
console.log(util.inspect(dogs, { showHidd
n: true, depth: null }));
console.log(util.inspect(mice, { showHidden: true, depth: null }));
console.log(util.inspect(unicorns, { showHidden: true, depth: null }));```
Output
{ [Function: cats]
[length]: 2,
[name]: 'cats',
[prototype]: cats { [constructor]: [Circular] } }
{ [Function: dogs]
[length]: 2,
[name]: 'dogs',
[prototype]: dogs { [constructor]: [Circular] } }
{ [Function: mice]
[length]: 0,
[name]: 'mice',
[prototype]: mice { [constructor]: [Circular] } }
{ [Function: unicorns]
[length]: 3,
[name]: 'unicorns',
[prototype]: unicorns { [constructor]: [Circular] } }
I talked with @jasnell about this on Monday, so I'm tagging him on this :)
When using
util.inspectfor functions, the output length value seems to indicates the number of parameters in the inspected function.Where things break is with functions that have default values. Below is a straight-forward proof
of concept that demonstrates the incorrect behavior. I assume with is related to the addition of the
=signand commas which may or may not be param separators.
Code
Output