JavaScript:JSLint 抛出“只读”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3705035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 02:00:30  来源:igfitidea点击:

JavaScript: JSLint throws "Read Only

javascriptobjectliteralsjslint

提问by stevek

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

我的代码:
注意:为了更好的可读性,在下面的代码片段中声明了 Slider 对象但省略了

"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)


这就是 JSLint 产生的(以及其他两个 Objects SliderInstance 和 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?


我如何满足 JSLint 的要求?什么是“只读”。意思是?

回答by glebm

Try this:

试试这个:

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

Informs JSLint that these globals are assigned intentionally.

通知 JSLint 这些全局变量是有意分配的。

回答by Luke Schafer

use

利用

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

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

请参阅“全局变量”下的doco-“true”表示此文件可以分配给这些变量。