Fix error in spectrum color picker

跟風遠走 提交于 2019-12-12 05:47:43

问题


I implemented spectrum color picker, and I'm trying to fix up the JSLint errors. I have 2 types of errors which I can't seem to fix. Here are the errors

  • 'var' was used before it was defined

  • Move the invocation into the parens that contain the function

Here's the code with the errors:

(function (factory) {
    "use strict";

    if (typeof define === 'function' && define.amd) { // AMD
        define(['jquery'], factory);
    } else if (typeof exports === "object" && typeof module === "object") { // CommonJS
        module.exports = factory;
    } else { // Browser
        factory(jQuery);
    }
})(function($, undefined) {
    "use strict";
   ...

define, exports, and module all have the error that it's not defined.

Then the second function: })(function($, undefined) { has the 2nd error mentioned above. So I checked up that error, and I tried what it said: }(function ($, undefined) ) { I moved the closing parenthesis to the end, and I now get the following error:

Expected '{' and instead saw '}'.

How can I fix the 2 errors mentioned above?


回答1:


Converting })(function($, undefined) { into }(function ($, undefined) ) { is erroneous because you need to move the {} inside the parentheses as well, like so:

(function() {
    ...
}(function() { ... }));

With regards to the undefined errors you're getting, just put this comment at the top of your JS file:

/*global define, module, exports*/

Feel free to add some other common variables if you need to exclude them as well:

/*global define, module, exports, document, window, alert, console, require*/


来源:https://stackoverflow.com/questions/34167361/fix-error-in-spectrum-color-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!