Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: JSLint throws "Read Only

Tags:

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?

like image 209
stevek-pro Avatar asked Sep 13 '10 22:09

stevek-pro


People also ask

Why is my variable read-only?

The JavaScript strict mode-only exception "is read-only" occurs when a global variable or object property that was assigned to is a read-only property.

What does Js lint do?

JSLint takes a JavaScript source and scans it. If it finds a problem, it returns a message describing the problem and an approximate location within the source. The problem is not necessarily a syntax error, although it often is. JSLint looks at some style conventions as well as structural problems.

What does read-only mean in JavaScript?

A read-only property means it cannot be overwritten or assigned to. Any such assignment will silently do nothing in non-strict mode. E.g.: var obj = {}; Object.


2 Answers

Try this:

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

Informs JSLint that these globals are assigned intentionally.

like image 112
glebm Avatar answered Sep 21 '22 17:09

glebm


use

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

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

like image 21
Luke Schafer Avatar answered Sep 20 '22 17:09

Luke Schafer