You should try to think in terms of modules, functions are something more low-level in this context. You define modules, requiring them later returns their public "interface" as an object with some properties, which may happen to be functions.
What I found useful was a "static utils module" pattern:
utils.js
define(function () {
return {
showMessage: function (text) {
alert(text);
},
foo: function () {
alert('bar');
}
}
})
Or a simplified equivalent: (-> docs)
utils.js
define({
showMessage: function (text) {
alert(text);
},
foo: function () {
alert('bar');
}
});
Then, inside your main.js:
define(['utils'], function (Utils) {
Utils.showMessage('!');
})
If you end up with too many dependencies (that usually indicates your module is doing too much, by the way) you can use the sugar syntax instead:
define(function (require) {
var Utils = require('utils');
Utils.showMessage('!');
})