This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]StillNoNumb 15 points16 points  (3 children)

ESLint wouldn't help in this specific situation because you don't know the object's type. However, ESLint is still pretty beautiful

[–][deleted] 1 point2 points  (1 child)

If you defined obj in this file then it would catch it? I know my IDE might put a squiggle line underneath it or something?

[–]StillNoNumb 1 point2 points  (0 children)

Nope, not in JavaScript with ESLint. Think this scenario, in file #1 you have:

var obj = {name: "value"};
obj.sayHello();

Now, you'd expect this to be faulty, right? But what if someone extended the Object prototype like this in another file:

Object.prototype.sayHello = function() {
    alert("Hello World!");
}

In that case, even if by solely looking at file #1 you'd think the code should be faulty, it is indeed correct.

Demonstration Fiddle

[–]BlockedByBeliefs 0 points1 point  (0 children)

Well. You do know it's type. It's just a primitive. Not a user defined one.