1、静态方法:在构造函数本身上定义的方法,只能通过构造函数本身调用,new出来的对象不能够调用。
function f1(){}
f1.static = function(){
console.log("我是一个静态方法");
}
f1.static();
2、动态方法:也叫做实例方法,它是通过prototype原型对象添加的,所有的实例对象都能够继承调用。通过先定义一个引用变量,指向构造函数定义的新对象,数对象中的属性 prototype可以想成一个指针,指向一个方法。
function f2(){}
f2.prototype.instance = function(){
console.log("我是一个动态方法");
}
console.log(f2)
debugger
var a = new f2();
a.instance();
3、实例
function Person(name,age){
debugger
this.name = name
this.age = age
}
Person.prototype.show = function(){
debugger
console.log(this.name,this.age)
}
console.log(Person)
debugger
let per = new Person('gsy','18')
console.log(per)
Person.eat = function(){
console.log('eat--',this.name,this.age)
}
console.log(Person)
debugger
Person.eat();