small medium large xlarge

Back to: All Forums  CoffeeScript
Mark1_pragsmall
05 Aug 2011, 16:17
R. Mark Volkmann (13 posts)

In the gray box at the top of page 27, it’s implied that you’re going to explain how these differ. However, after reading that I still don’t see how they differ.

Trevor_burnham__goofy_headshot__pragsmall
05 Aug 2011, 23:37
Trevor Burnham (54 posts)

Sorry, I guess I don’t quite make the point explicitly: If you write @a or= b@, and @a@ is a falsey value (like @false@ or @0@), then @a@ will be set to @b@, because @a or b == b@. But if you write @a ?= b@, then @a@ will only be set to @b@ if @a?@ fails—which only happens if @a@ is @null@ or @undefined@.

It’s common to see JS code set default options using statements along the lines of @antialias = antialias or defaults.antialias@ (in CoffeeScript, @antialias or= default.antialias@), but that won’t work if you @antialias@ is @false@ and you want that value to override the default. That’s why I say that @?=@ is generally more useful than @or=@.

You must be logged in to comment