javascript - Event listener callback does not fire via a normal function call -


i'm sure there's reasonable explanation this, cannot figure out - bit of guidance appreciated.

i have following code using backbone:

var examplecollection = backbone.collection.extend({     exampleevent: function() {console.log('event fired')} });  var exampleview = backbone.view.extend({     el:'body',     onexampleevent: function() {console.log('listener heard it')},     initialize: function() {         this.listento(this.collection,'exampleevent',this.onexampleevent);     } });  var testcollection = new examplecollection; var testview = new exampleview({collection:testcollection}); 

in console, when enter command testcollection.trigger('exampleevent') onexampleevent callback function fires . however, when enter command testcollection.exampleevent() exampleevent function fires onexampleevent callback function doesn't.

if explain why happens appreciate have been looking while , can't figure out.

many in advance.

just think - when call

 testcollection.exampleevent() 

you execute it, and... nothing. when

 testcollection.trigger('exampleevent') 

is called, execute function , every listener.


Comments