weepy / kaffeine

Extended Javascript for Pros
http://weepy.github.com/kaffeine/
MIT License
180 stars 16 forks source link

Add Existential Operator #25

Open akidee opened 13 years ago

akidee commented 13 years ago

In CS, this a feature I heavily use when writing templates, and it is very useful, since it makes your code more safe (because null/undefined will throw an error on accessing properties)

Example:

zip = lottery.drawWinner?().address?.zipcode
weepy commented 13 years ago

I did once upon a time have one (actually I invented the one in CoffeeScript :)

I should be able to bring it back as I agree, it was useful. I decided to make it a little simple here though : more like a non-strict comparison with null, so your example would work like :

zip = (_ex = lottery.drawWinner()) != null && _ex.address && _ex.adress.zipcode
weepy commented 13 years ago

I've put up a gist to explore the possibilities here :

https://gist.github.com/923899