const func0 = Function("return;");
const func1 = Function("x", "return x;");
const func2 = Function("x, y", "return x + y;");
const func3 = Function("x, y, z", "return x + y + z;");
console.log(func0.prototype.constructor);
// 出力:ƒ anonymous(
// 出力:) {
// 出力:return;
// 出力:}
console.log(func0.length);
// 出力:0
console.log(func0.name);
// 出力:anonymous
console.log(func0.prototype);
// 出力:constructor: ƒ anonymous( )
// 出力:__proto__: Object
console.log(func1.prototype.constructor);
// 出力:ƒ anonymous(x
// 出力:) {
// 出力:return x;
// 出力:}
console.log(func1.length);
// 出力:1
console.log(func1.name);
// 出力:anonymous
console.log(func1.prototype);
// 出力:constructor: ƒ anonymous(x )
// 出力:__proto__: Object
console.log(func2.prototype.constructor);
// 出力:ƒ anonymous(x, y
// 出力:) {
// 出力:return x + y;
// 出力:}
console.log(func2.length);
// 出力:2
console.log(func2.name);
// 出力:anonymous
console.log(func2.prototype);
// 出力:constructor: ƒ anonymous(x, y )
// 出力:__proto__: Object
console.log(func3.prototype.constructor);
// 出力:ƒ anonymous(x, y, z
// 出力:) {
// 出力:return x + y + z;
// 出力:}
console.log(func3.length);
// 出力:3
console.log(func3.name);
// 出力:anonymous
console.log(func3.prototype);
// 出力:constructor: ƒ anonymous(x, y, z )
// 出力:__proto__: Object
function funcA(x, y = 20, z = 30) {
console.log(arguments.length);
}
function funcB(...args) {
console.log(arguments.length, args.length);
}
console.log(funcA.name);
// 出力:funcA
console.log(funcA.length);
// 出力:1
funcA(1);
// 出力:1
funcA(1, 2);
// 出力:2
funcA(1, 2, 3);
// 出力:3
console.log(funcB.name);
// 出力:funcB
console.log(funcB.length);
// 出力:0
funcB();
// 出力:0 0
funcB(1);
// 出力:1 1
funcB(1, 2);
// 出力:2 2
funcB(1, 2, 3);
// 出力:3 3