将 nowjs 代码与应用程序分离的正确方法。(coffee/js)

发布于 2025-01-03 17:59:38 字数 529 浏览 1 评论 0原文

有没有正确的方法将我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

命硬 2025-01-10 17:59:38

通过这样做,我能够得到一些东西:

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

对我来说看起来更干净。

I was able to get something working by doing this:

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

In nowtes/index.coffee

exports.distribute_event = (activity, day) ->
  everyone.now.receive_event @now.name, activity, day

Looks much cleaner to me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文