バックボーンアプリケーションを作成しています。ルータークラスのメソッド(ルート)のリストを装飾するために使用できる認証済みデコレーターを作成したいと思います。
だから私はいくつかの方法でルーターを持っていて、このようなものを試しました。ただし、デコレーションしたいルートを呼び出すと、デコレータがアタッチされません。
class MyApp extends Backbone.Router
routes:
'' : 'home'
'foo' : 'foo'
'bar' : 'bar'
authenticated: ['foo', 'bar']
initialize: ->
@decorateAuthenticatedFunctions()
decorateAuthenticatedFunctions: =>
_.each @authenticated, (method)=>
@[method] = (args)=>
if @authorized()
@[method].apply @, args
else
@navigate '', true
authorized: =>
@user? and @user.loggedIn
foo: =>
#do stuff
bar: =>
#do stuff
この問題を解決するにはどうすればよいですか?