是否有正确的方法将我的nowjs代码与app文件分开?
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
答案 0 :(得分:1)
通过这样做,我得到了一些工作:
global.now = require("now")
global.everyone = now.initialize app,
socketio:
transports: [ 'xhr-polling', 'jsonp-polling' ]
nowtes = require "./nowtes"
everyone.now.distribute_event = nowtes.distribute_event
在nowtes / index.coffee中
exports.distribute_event = (activity, day) ->
everyone.now.receive_event @now.name, activity, day
对我来说看起来更干净。