我正在尝试将其翻译成 Coffeescript:
App.IndexView = Ember.View.extend(InfiniteScroll.ViewMixin, {
didInsertElement: function(){
this.setupInfiniteScrollListener();
},
willDestroyElement: function(){
this.teardownInfiniteScrollListener();
}
});
我的第一个方法是:
Whistlr.OrganizationsView = Em.View.extend
InfiniteScroll.ViewMixin
didInsertElement: ->
@setupInfiniteScrollListener()
willDestroyElement: ->
@teardownInfiniteScrollListener()
但它引发了意外的缩进错误。所以我尝试了这个:
Whistlr.OrganizationsView = Em.View.extend InfiniteScroll.ViewMixin
didInsertElement: ->
@setupInfiniteScrollListener()
willDestroyElement: ->
@teardownInfiniteScrollListener()
这给了我这个错误:
TypeError: InfiniteScroll.ViewMixin is not a function
如果我使用纯js,它工作得很好。所以问题肯定出在 Coffeescript 格式上。我无法弄清楚发生了什么,甚至无法正确地寻找解释。任何指示将不胜感激!
最佳答案
尝试
Whistlr.OrganizationsView = Em.View.extend InfiniteScroll.ViewMixin,
didInsertElement: -> @setupInfiniteScrollListener()
willDestroyElement: -> @teardownInfiniteScrollListener()
.extend
的第二个参数需要是 JavaScript 对象。
关于javascript - Coffeescript 缩进问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18922190/