lundi 18 juillet 2016

Object literal pattern callback and this confusion


var App = {
  method : function (value, callback) {
    console.log(value);  
    if (typeof callback === 'function') {
      //here
      callback.call( this );
    } 
  } 
} 

App.method('Hey there', function(){
  console.log('callback was executed!');
}); 

Why do I can't do callback(), but have to call(this) for the callback?


Aucun commentaire:

Enregistrer un commentaire