2

これを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 の書式設定にあります。何が起こっているのか、あるいは説明を適切に検索する方法さえ理解できません。任意のポインタをいただければ幸いです!

4

2 に答える 2

0

これは、JS を Coffeescript に簡単に変換したものです。「Try Coffeescript」ブラウザー ウィンドウに貼り付けると、同じ JS が生成されます (リターンが追加されます)。余分な (){} は私の利益のためであり、CS のものではありません。彼らは、これが の呼び出しでextendあり、2 つの引数、1 つはオブジェクト属性、もう 1 つは 2 つの関数定義を持つオブジェクトであることを明確にしています。

App.IndexView = Ember.View.extend(
    InfiniteScroll.ViewMixin,
    {
    didInsertElement: ()  ->
        @setupInfiniteScrollListener()
    willDestroyElement: () ->
        @teardownInfiniteScrollListener()
    }
)
于 2013-09-21T19:21:28.830 に答える