JS 函数 的 属性 和 方法

函数是 Javascript 中特殊的对象,可以拥有属性和方法

类似一般对象,可直接以 函数名 方式调用。

属性

length

参数个数

1
2
3
4
5
function add(x,y){
console.log(arguments.length)//3
console.log(add.length);//2
}
add(1,2,3);

name

prototype

指向一个 prototype object

1
2
3
4
5
function fn(){};
var obj = new fn;

fn.prototype.a = 1;
console.log(obj.a);//1

将函数用做构造函数时,新创建的对象 会以 这个属性指向的对象 作为原型 (prototype)

方法

apply()和call()

https://www.cnblogs.com/Renyi-Fan/p/8942739.htm