What's the Difference between Template.Instance() vs template.data?


#1

When creating a Meteor event handler, what’s the difference between…

‘click .something’: function(e,t){
var data = t.data
}
vs

‘click .something’: function(e,t){
var data = Template.Instance().data
}
They both seem to bring up the same data. Is there a reason why I should one or the other?


#2

They are the same. Template.instance() is intended to work from everywhere, but the template argument only works from event handlers.


#3

@ashah888 Note that Template.instance() will not work in asynchronous calls, so you need to be careful in situations like:

'click': function (e, t) {
   doSomethingAsynchronous(function () {
      // async task done
      var data = Template.instance(); // will throw!
   });
}