define(['backbone'],function(Backbone){ var navController = Backbone.Router.extend({ routes : { 'test':'test', 'nav/:path': 'gotoNav' }, initialize:function(){//constructor console.log(123); }, test:function(){alert(1)}, gotoNav:function(path){ console.log(path); } }); return navController; })
今天写一个backbone router, 结果发现routes没有生效, 因为长时间没用了 html
开始时候发现 函数
状况1: spa
Backbone.history.start() 忘记调用了 code
状况2: router
手贱,心血来潮把初始化方法写成 constructor 结果不生效,修改 initialize 后正常工做 htm
constructor / initialize new Router([options]) When creating a new router, you may pass its routes hash directly as an option, if you choose. All options will also be passed to your initialize function, if defined.
我XX 我还觉得这2个方法是一样效果的呢, 如今看来 initialize 应该是backbone constructor 的回调函数(猜想啊) 闲情能够看backbone源码 backbone
记录一下吧,省的之后又忘记了 回调函数