Javascript calling a function from another javascript file -
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
'm' used before defined.
this error because you're defining m
global variable in 1 file, , attempting invoke in another. because global variables sign of code-smell, jslint makes declare them. there few options this. one, prepend file 2
/*global m*/
, , should stop complaining.
missing 'new'.
this based on variable conventions. in javascript, typically name constructor functions using camelcase. because constructor functions intended called new
keyword, it's detecting error. in case, best option rename m
m
.
for more information on configuration , other jslint
topics, see this page. alternatively, if have @ in matter, strongly suggest checking out jshint instead.
Comments
Post a Comment