I was searching in stackoverflow and the web, could not get proper results or explanation siting difference between these three methods.
As far as i understand, they all do the same executing the function/method in different context.
var google = {
makeBeer : function(arg1,arg2){
alert([arg1, arg2]);
}
}
google.makeBeer('water','soda');
This is my normal function of the google object. Now when i make use of call and bind method here, here is the output.
var google = {
makeBeer: function (arg1, arg2) {
alert([arg1, arg2]);
}
}
google.makeBeer('water', 'soda');
function yahoo() {}
var yah = new yahoo();
google.makeBeer.call(yah, 'pepsi', 'coke');
function msn() {
}
var msn = new msn();
google.makeBeer.call(msn, 'sprite', 'limca');
I still don't see a purpose of doing this, i can go-ahead and call the google.makeBeer three times with different arguments.
Can anyone enlighten me more over this.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…