'for in' error from jslint

A

Andrew Poulos

JSLint tells me that "The body of a for in should be wrapped in an if
statement to filter unwanted properties from the prototype." at
for (keys in this.vars) {

Could somebody explain what unwanted properties are being referred to?

Andrew Poulos
 
D

Dmitry A. Soshnikov

JSLint tells šme that "The body of a for in should be wrapped in an if
statement to filter unwanted properties from the prototype." at
š š for (keys in this.vars) {

Could somebody explain what unwanted properties are being referred to?

Andrew Poulos

"in" operator (11.8.7) analyses also prototype chain of an object.

Object.prototype.x = 10;
var a = {}; // "empty" object
for (var k in a) print(k); // x

so the hint says:

for (var k in a) if a.hasOwnProperty(k) {
print(k);
}
 
T

Thomas 'PointedEars' Lahn

Andrew said:
JSLint tells me that "The body of a for in should be wrapped in an if
statement to filter unwanted properties from the prototype." at
for (keys in this.vars) {

Could somebody explain what unwanted properties are being referred to?

User-defined, thus enumerable, properties inherited from an object in the
prototype chain (usually the object constructor's prototype). Discussed ad
nauseam before. Google is your friend [psf 6.1], RTFM, RTFFAQ, STFW and so on!


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top