Tuesday, March 1, 2016

You should avoid the with keyword in javascript

While watching one of Kyle Simpson workshops, he tried to explain why it is important to avoid using with key word, he even called it more evil than eval (eval is modifying existing lexical scope, the with key creating a whole new lexical scope). In the example below 'd' is not an attribute in obj, javascript will create a 'd' variable in the global scope instead of adding it to obj.


No comments:

Post a Comment