问题
I am using jQUery . And in jslint, I keep on
'$' was used before it was defined.
or
document was used before it was defined.
I know I can stop those from showing up by using
/*jslint browser: true*/
/*global $, jQuery*/
But I wanted to actually fix this through coding if possible. So, I did like before.
var $, document;
$(document).ready(function () {
"use strict";
However, now it says
Two warnings
1 Redefinition of '$'.
1 Redefinition of 'document'.
in jshint. Is there a coding that I can use to please both jshint and jslint?
回答1:
Please use jslint comments. The following suggestion uses a few tricks. Having tricks in your code won't help for maintainability. Here is the code:
var myApplication = function () {
"use strict";
var $ = this.$, document = this.document, console = this.console;
$(document).ready(function () {
//...
console.log("test");
});
};
myApplication.call(this);
回答2:
You cannot, and don't have to, fix it by coding. $
does in fact exist as global variable in a different file. That's exactly what /*global ... */
is for.
来源:https://stackoverflow.com/questions/25460567/how-to-fix-was-used-before-it-was-defined-in-both-jslint-and-jshint-using-co