将 nowjs 代码与应用程序分离的正确方法。(coffee/js)
有没有正确的方法将我的 nowjs 代码从应用程序文件中分离出来?
everyone = require("now").initialize app, { socketio: { transports: ['xhr-polling', 'jsonp-polling'] } }
everyone.now.distribute_event = (event, day) ->
everyone.now.receive_event @now.name, event, day
我猜你会在其他地方定义函数,比如路由?像下面这样的东西?
nowtes = require('./nowtes')
everyone = require("now").initialize app, { socketio: { transports: ['xhr-polling', 'jsonp-polling'] } }
everyone.now.distribute_event = nowtes.distribute_event
Is there a proper way to separate out my nowjs code from the app file?
everyone = require("now").initialize app, { socketio: { transports: ['xhr-polling', 'jsonp-polling'] } }
everyone.now.distribute_event = (event, day) ->
everyone.now.receive_event @now.name, event, day
I'm guessing you would define the functions elsewhere like routes? Something like below?
nowtes = require('./nowtes')
everyone = require("now").initialize app, { socketio: { transports: ['xhr-polling', 'jsonp-polling'] } }
everyone.now.distribute_event = nowtes.distribute_event
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过这样做,我能够得到一些东西:
在 nowtes/index.coffee
对我来说看起来更干净。
I was able to get something working by doing this:
In nowtes/index.coffee
Looks much cleaner to me.