JavaScript: JSLint throws "Read Only

北战南征 提交于 2019-12-04 08:55:08

问题


My code:
note: the Slider Object is declared but omitted in the snippet below for better readability

"use strict";
/*global arrayContainer, SliderInstance, DomObjects */
arrayContainer = new Slider.constructArray();
SliderInstance = Object.beget(Slider);
DomObjects = {

    animationContainer: document.getElementById('animationContainer'),
    buttonRight: document.getElementById('buttonRight'),
    buttonRightDots: document.getElementById('buttonRightDots'),
    ieEffectImg: document.getElementById('ie_effectIMG')        
};


This is what JSLint produces (and on the other two Objects SliderInstance and DomObjects)

Error:
Problem at line 3 character 1: Read only.

arrayContainer = new Slider.constructArray();

Problem at line 3 character 1: Stopping. (27% scanned).


How do I satisfy JSLint's requirements? What does "Read only." mean?


回答1:


Try this:

 /*global arrayContainer:true, SliderInstance:true, DomObjects:true, document, Slider*/

Informs JSLint that these globals are assigned intentionally.




回答2:


use

/*global arrayContainer:true, SliderInstance:true, DomObjects:true */

see doco under 'Global Variables' - the 'true' says that this file can assign to those variables.



来源:https://stackoverflow.com/questions/3705035/javascript-jslint-throws-read-only

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