我正在编写一个骨干应用程序,并且我想写一个经过身份验证的装饰器,我可以用它来装饰路由器类中的一组方法(路由)。在CoffeeScript类中装饰函数
所以我有一个路由器有几个方法,并尝试过这样的事情。然而,当我打电话给我想要装饰的路线时,修饰器并未连接。
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的警报。 –