I am currently using require.js and have a collection of functions that I utilize in various locations. The way I define these functions is as follows:
define(function (require) {
"use strict";
var $ = require('jquery');
var UsefulFuncs = {};
UsefulFuncs.hideAlert = function() {
$('.alert').hide();
};
UsefulFuncs.loadURL = function (url){
navigator.app.loadUrl(url, { openExternal:true });
return false;
};
UsefulFuncs.linkClicked = function (e) {
e.preventDefault();
var url = $(e.currentTarget).attr("rel");
this.loadURL(url);
};
return UsefulFuncs;
});
Then, within my backbone view, I invoke a function from the library with:
UsefulFuncs = require('app/utils/useful_func'),
....
UsefulFuncs.linkClicked
This process works well for any standalone function in the library like hideAlert(). However, when one function in the library references another function, such as linkClicked() calling loadURL(), I encounter an error:
Uncaught TypeError: Object [object Object] has no method 'loadURL'.
Do you have any suggestions on how I can reference loadUrl() properly?