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


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

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

‘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?


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


@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!