Backbone jsを学習しようとしていますが、bindAll/bind関数で提供されるアンダースコアライブラリと関数で提供されるjQueryを使用したイベントバインディングの違いを理解するのに問題があります。これがCoffeescriptの例です:
class Raffler.Views.Entry extends Backbone.View
template: JST['entries/entry']
tagName: 'li'
events:
'click': 'showEntry'
initialize: ->
@model.on('change',@render,this)
@model.on('highlight',@highlightWinner,this)
showEntry: ->
Backbone.history.navigate("entries/#{@model.get('id')}", true)
highlightWinner: ->
$('.winner').removeClass('highlight')
@$('.winner').addClass('highlight')
render: ->
$(@el).html(@template(entry: @model))
this
This is a snippet of code from Ryan Bate's RailsCasts' on Backbone.js
Seems to me that the same code can be written using the underscore bindAll and bind functions as follows:
class Raffler....
...
initialize: ->
_bindAll @, 'render', 'highlightWinner'
@model.bind 'change',@render
@model.bind 'highlight',@highlightWinner
...
質問:
- これら2つは機能的に同等ですか?
- はいの場合、jQueryコードははるかに明確で明確に見えます。これは個人的な好みの問題ですか?
よろしくお願いします。
バーラト