25

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?

2 Answers 2

49

Try this:

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

Informs JSLint that these globals are assigned intentionally.

Sign up to request clarification or add additional context in comments.

4 Comments

You've got a keen eye and good understanding of JSLint. That worked nicely. JSLint Docs say: "Each name can optionally be followed by a colon and either true or false, true indicated that the variable may be assigned to by this file, and false indicating that assignment is not allowed which is the default." Some interesting questions arise out of this answer. 1) Why doesn't it matter what boolean I assign to the global document object? And more importantly: 2) Why does JSLint or JavaScript care about -where- I assign global objects?
Oh, this is to avoid assigning global object by accident (e.g. forgetting the var keyword and writing document = $('#attachment_document')
Also, JavaScript itself does not care where you assign those, only JSLint does.
FYI make sure there is no space after /* or before the closing */, spent ages trying to work out why the directive was not being used.
6

use

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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.