-2

File 1

var M = function (speech) {
  "use strict";
  document.getElementById("speech").innerHTML = speech.toString();
};

File 2

$("#test").click(function () {
  M("hello");
});

JS lint probelms v http://puu.sh/j8AOo/a24a88825b.png

Switch
  • 11
  • 4
  • Is there a question somewhere? – jcoppens Jul 22 '15 at 14:00
  • Are you meaning to ask how/if it is possible to use two JS libraries and call one from the other? If so, you will need to include a reference for the seond JS file in the first and/or have a reference to the other in both. – Kenneth Salomon Jul 22 '15 at 14:07
  • possible duplicate of [Can we call the function written in one JavaScript in another JS file?](http://stackoverflow.com/questions/3809862/can-we-call-the-function-written-in-one-javascript-in-another-js-file) – spenibus Jul 22 '15 at 14:09

1 Answers1

1

'M' was used before it was defined.

This error is because you're defining M as a global variable in one file, and attempting to invoke it in another. Because global variables are often a sign of code-smell, JSLint makes you specifically declare them. There are a few options to do this. For one, you could prepend File 2 with /*global M*/, and it should stop complaining.

Missing 'new'.

This is based on variable conventions. In JavaScript, we typically only name constructor functions using CamelCase. Because constructor functions are intended to be called with the new keyword, it's detecting this as an error. In this case, your best option is probably to just rename M to m.

For more information on configuration and other JSLint help topics, see this page. Alternatively, if you have any say at all in the matter, I would strongly suggest checking out JSHint instead.

jmar777
  • 38,796
  • 11
  • 66
  • 64