arrow_upward
Javascript Keyword "With"
#1
Why dont people use "with" more often in javascript? Is it just not helpful?



#2
What do you mean?



#3
It's not recommended and confusing



#4
Hello,

You use "with" keyword for the context manager.

+



#5
In javascript, "with" is confusing and ambiguous. I don't know about other languages, but in Visual Basic, there is an extremely clear of the context and which variables you're requesting from the context. In JS, you have something like this:

Code:
with (employee) {
     ID = 1;
     name = "John";
}


It's not clear whether you're attributing to employee.name or some name variable outside of the block scope. In Visual Basic, this is solved in a genius way. It requires a dot to "search" on the context variable and there's no ambiguity.

Code:
With employee
     .ID = 1
     .name = "John"
End With



#6
It's especially telling that JS supersets like TypeScript don't even allow you to use `with`, even if you're using it to access statically typed properties on an object. MDN has a good writeup on it:

RE: Javascript Keyword "With".

Registered Members Only

You need to be a registered member to see more on RE: Javascript Keyword "With".
Login or Sign up to get access to a huge variety of top quality leaks.