Any opinions about adding a Ruby-like ||= operator to EcmaScript?
# Andy Earnshaw (10 years ago)
Plenty of opinions about it here: esdiscuss.org/topic/is-much-needed ;-)
# Claude Pache (10 years ago)
Le 29 juil. 2015 à 13:23, Behrang Saeedzadeh <behrangsa at gmail.com> a écrit :
For example:
obj.property ||= "value";This would only assign "value" to obj.property if property is undefined or null.
For me, that syntax suggests strongly: Assign value to obj.property if obj.property is falsy. I'd rather want to write:
obj.property ??= value
where ?? could also be used as binary operator with the semantics you've guessed.
# Behrang Saeedzadeh (10 years ago)
I am not very fussed about the syntax as long as the facility is in the language. Any chance this gets included in EcmaScript 2016?
For example:
This would only assign "value" to obj.property if property is undefined or null.
For example: obj.property ||= "value"; This would only assign "value" to obj.property if property is undefined or null. -- Best regards, Behrang Saeedzadeh -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150729/f3fc6658/attachment.html>