Why do you need to avoid with statement?

Posted by Jessica Taylor | Updated on

JavaScript’s with statement was intended to provide a shorthand for writing recurring accesses to objects. So it can help reduce file size by reducing the need to repeat a lengthy object reference without performance penalty. Let’s take an example where it is used to avoid redundancy when accessing an object several times.

Using with it turns this into:

But this with statement creates performance problems since one cannot predict whether an argument will refer to a real variable or to a property inside the with argument.

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers