【发布时间】:2012-06-15 22:14:21
【问题描述】:
我正在编写一个主干应用程序,我想编写一个经过身份验证的装饰器,我可以用它来装饰路由器类中的方法(路由)列表。
所以我有一个带有几种方法的路由器,并尝试过类似的方法。但是,当我调用我想要装饰的路线时,装饰器没有附加。
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
我该如何解决这个问题?
【问题讨论】:
-
你确定
initialize被调用了吗?在那里添加一个console.log的警报以确保。
标签: javascript backbone.js coffeescript decorator