Robert FisherJust thinking out loud EcmaScript idiomsIf you register and log in you can add comments to my pages. If viewing the main blog page, click the # underneath an entry to comment on it. Defaults This will set y to zero if x is undefined or x if x is defined:
(Be careful when using this idiom with strings.) This one is kind of weird. I haven't yet seen a case where it is useful. It will (I think) set y to undefined if x is undefined. Otherwise y will be set to 1.
Keyword arguments Use literal objects for keyword parameters:
In
A function that can make constructing sets a bit simpler.
Delay & force Without macros to create our own special forms, you have to make the λ explicit. So, delay & force don't look as magical as they do in Scheme. (u_u) Delay:
Force:
Or, if you want to look clever:
EcmaScript kludges: The
Prefer String.join to +
back to Scheme & other programming stuff last updated 2 months ago # |