2 ms·
That use of `with` makes me squeamish as hell. Also, on the topic of the "eta" function, it's odd that the author seems unaware of existing implementations of
by mistercow 15y ago
That use of `with` makes me squeamish as hell.
Also, on the topic of the "eta" function, it's odd that the author seems unaware of existing implementations of `bind`.
- invisiblefunnel 15y agoCrockford warns against ever using `with` in a talk he gave last year. Discussion on `with` at 19m58s: http://ontwik.com/javascript/douglas-crockford-javascript-programming-style-and-your-brain/ http://ontwik.com/javascript/douglas-crockford-javascript-pr... Edit: He says it's not that `with` isn't useful, but that there is never a case where it isn't confusing.
- mistercow 15y agoThat is very well put. It is a shame that JS got its scoping so very upside-down, because it means that tiny changes in code can cause incredibly confusing and initially undetectable bugs. `with` is basically an infected bandaid on a broken system. It seems like it's helping until you notice the smell.
- insin 15y agoSure there are - why are so many Crockford pronouncements taken as a signal to stop thinking? Notice that his "with is bad" examples (which are usually bad examples and bad usages [1]) always involve contrived examples of potentially ambiguous assignment - one of the more useful ways to use `with` is with objects whose properties are DSL-like functions, named in such a way that there's no mistaking their origin and with no ambiguous assignment involved. Simple example with includes: https://github.com/insin/DOMBuilder/blob/master/examples/reddit_posts.html#L18-47 https://github.com/insin/DOMBuilder/blob/master/examples/red... More extensive example of inheritable templates for a CRUD admin app: https://github.com/insin/sacrum/blob/master/lib/sacrum/admin.js#L277-439 https://github.com/insin/sacrum/blob/master/lib/sacrum/admin... [1] http://webreflection.blogspot.com/2009/12/with-worlds-most-misunderstood.html http://webreflection.blogspot.com/2009/12/with-worlds-most-m...