My Profile Photo

Rich Werden

Web Developer & Software Engineer


A site for Rich to write about code and show some completed projects for future reference...


#TIL: Javascript's Deprecated `with` syntax:

Got asked to explain this recently and I [had to look it up on MDN][mdnwith]. Using with was deprecated as of ES5 and its use is now bad-practice, can lead to unintended results, and is literally rejected in ‘strict-mode’.

Basically, with(someObj{}){/*. . . */} told the interpreter that for any unknown methods/references in the following obj{}’s scope, use whatever is in the (arg) as the source for looking things up…

Given: var c = 10; - Writing with(Math){ a=c*PI; b=floor(a*10); } will make all of the unknowns like PI and floor be looked up in the Math object as Math.floor and Math.PI

Random. ¯\(ツ)/¯ But we’ve got enough headaches over this, so I can see why with was dropped. Good choice ECMA. My brain thanks you.