201510222231_《JavaScript——函数——4种方式调用》
1.方法调用模式;
形如:
var dog = {
name: "aWang",
speak: function(){
//to do
}
};
dog.speak();
------------------------------------------------------------------
2.函数调用模式;
形如:
var speak = function(){
//to do
};
speak();
------------------------------------------------------------------
3.构造器调用模式;
形如:
var speak = function(){
//to do
};
var obj = new speak();
obj.speak();
------------------------------------------------------------------
4.apply调用模式;
形如:
var sum = function(a ,b){
return a + b;
};
sum.apply(this,[a,b]);
前端-语言