I have an AngularJS application with RequireJS and JSHint. There I have a controller MyCtrl
:
define([
'myDependecy'
], function(app) {
'use strict';
app.controller('MyCtrl', function($scope) {
doSomething();
var test = MyTest.doIt();
});
});
myDependency
is a JavaScript file which has following content:
var MyTest = (function() {
var doIt = function() {
// …
};
return {
doIt: doIt
}
});
function doSomething() {
console.log("test");
}
The problem with JSHint is that I get the error messages 'MyTest' is not defined
and also 'doSomething' is not defined
. What can I do to solve this problem, because they are defined but JSHint don't know it.
Update
The problem seems to be the mix of AMD and Non-AMD modules. So the best solution in this case won't be the /* global … */
comment.
Update2
The problem occurs also in grunt serve:dist
which generates one big JavaScript file. So the problem is more "complex". The real problem has one more dependency. The MyTest
object literal is here:
(function(root) {
define("test1", ["test2"], function() {
return (function() {
var MyTest = (function () {
// …
}());
}).apply(root, arguments);
});
}(this));
And the implementation with the doIt
is defined in a similar define
block named test2
where the error occurs.