1. Function mode
function show(){
}
show()
var show=function(){
}
show()
2. Method Mode
var obj={
}
function show(){
}
obj.showFn=show;
obj.showFn();
3. Constructor pattern
function personFn(name){
this.name=name;
this.showName=function(){
console.log('name is'+this.name)
}
}
var person = new personFn ('yaozheng');
person.showName();
4. apply call mode
call apply to change the point of this
The difference between the knowledge point call and apply and how to use it
function Cat(){}
Cat.prototype={
food:"aaa",
showFood:function(){ alert(this.food) }
}
var blackCat=new Cat();
blackCat.showFood();
var whiteCat={food:'bbb'};
blackCat.showFood.apply(whiteCat);
the difference
obj.call(thisObj,[a,b,c])
obj.apply(thisObj,a,b,c)