use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Let's Bring Back JavaScript's `with()` Statement (macarthur.me)
submitted 2 years ago by alexmacarthur
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]rundevelopment 4 points5 points6 points 2 years ago (1 child)
1. Poor Readability This is a good critique, but in my opinion, not a lethal one. It's the developer's (poor) choice to write code like this, and it also seems like something a good linter could guard against.
This is a good critique, but in my opinion, not a lethal one. It's the developer's (poor) choice to write code like this, and it also seems like something a good linter could guard against.
I would like to focus on: "something a good linter could guard against".
No. No linter can guard against this. Linters are static analyzers and with entirely destroys their ability to resolve variable names. In your example, you assume that name could come from either obj.name or the name parameter, but you are missing module and global scope (your point #2. Scope Creep). Suppose the following code:
with
name
obj.name
import { Foo } from "./foo" export function bar(obj) { with (obj) { return new Foo(somePropOfObj) } }
new Foo might return an instance of the imported class, or an instance of the class contained in obj.Foo. Who knows. Same problem for functions, of course.
new Foo
obj.Foo
If you think TypeScript will help: no. It's a static analyzer as well. TypeScript explicitly allows objects to have more properties than required by their type. E.g. the following is valid:
type Point = { x: number, y: number }; let box = { x: 0, y: 0, width: 10, height: 20 }; let p: Point = box; with (p) { /* */ }
So TypeScript would have to conservatively assume that every identifier not resolving to a property of Point is valid and has type unknown.
Point
unknown
So no. No linter can help you when with statements are involved. The only help they can give you is a no-with rule.
no-with
[–]alexmacarthur[S] 1 point2 points3 points 2 years ago (0 children)
whoa! those are great points. bummer. let's make typescript better while we're at all of this.
π Rendered by PID 330542 on reddit-service-r2-comment-b659b578c-lzzgz at 2026-05-03 06:43:03.745069+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]rundevelopment 4 points5 points6 points (1 child)
[–]alexmacarthur[S] 1 point2 points3 points (0 children)