Search code examples
v8embedded-v8

What does the length parameter in v8::Function::New?


when creating a new function in v8, one can pass a length parameter (docs). But I couldn't find out what it is good for as it does not seem to have any direct effect...

v8::Function::New(ctx, callback, data, length);

Solution

  • JavaScript functions have a length property:

    function foo(a, b, c) {}
    var len = foo.length;  // 3
    

    When you create a function on the C++ side, the length parameter to v8::Function::New (or v8::FunctionTemplate::New) allows you to specify the value of the resulting function's length property.