最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SailsJS and global functions, variables - Stack Overflow

programmeradmin0浏览0评论

Just wondering how can I have an object which is accessible everywhere models, controllers etc in SailsJS. I need this mostly for some utility functions which I use quite often. Do you think that's a good idea?

EDIT: What's the remended way to do this

Just wondering how can I have an object which is accessible everywhere models, controllers etc in SailsJS. I need this mostly for some utility functions which I use quite often. Do you think that's a good idea?

EDIT: What's the remended way to do this

Share edited Jan 25, 2014 at 13:02 Petar Vasilev asked Jan 24, 2014 at 21:54 Petar VasilevPetar Vasilev 4,7556 gold badges47 silver badges78 bronze badges 2
  • then make a global utils object or use require or hide it as a property of another global. – dandavis Commented Jan 24, 2014 at 22:20
  • whats the remended way to do this, is it just go into bootstrap.js and do: global.utils = require('lib/utils'); ? – Petar Vasilev Commented Jan 24, 2014 at 22:35
Add a ment  | 

1 Answer 1

Reset to default 8

See the documentation for Services in the Sails docs. They sound like exactly what you're looking for--custom modules that are globalized for use throughout your app.

发布评论

评论列表(0)

  1. 暂无评论