views:

82

answers:

2

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 this requirement? What does "Read only." mean?

+1  A: 

Try this:

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

The idea is to tell JSLint that you are gonna assign those globals in the given file.

glebm
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?
Stephan Kristyn
Oh, this is to avoid assigning global object by accident (e.g. forgetting the var keyword and writing `document = $('#attachment_document')`
glebm
Also, JavaScript itself does not care where you assign those, only JSLint does.
glebm
A: 

use

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

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

Luke Schafer