向模板添加流星辅助方法的新旧方法

Old and new ways for adding meteor helper methods to template

我按照 Make Your First Meteor Application 一书,困惑地找到了以下段落:

"To begin, we’ll take an old approach for creating helper functions. This approach is deprecated, meaning it’s no longer officially supported, and by the time you’re reading these words, it may not work at all. "同时展示添加辅助函数的方法:

Template.leaderboard.player = function(){
return "Some other text"
}

不过,当我查看 Meteor 官方文档时,它说:

“每个模板都有一个本地可用的助手字典,此调用指定了要添加到模板字典中的助手。

示例:

Template.myTemplate.helpers({
  foo: function () {
    return Session.get("foo");
  }
});"

那么,不推荐使用的方法和新方法之间的唯一区别是用显式声明所有帮助器来替换一个接一个的帮助器声明吗?我找不到有关何时以及为何进行此更改的任何信息。

helpers API 的更改已在 v0.9.4 中引入:

Deprecate the Template.someTemplate.myHelper = ... syntax in favor of Template.someTemplate.helpers(...). Using the older syntax still works, but prints a deprecation warning to the console.

当前版本已经有一段时间了,我还没有看到任何当前教程中使用的旧版本,所以它可能会被忽略。