Skip to content

Instantly share code, notes, and snippets.

@ptomato
Last active September 22, 2020 00:22
Show Gist options
  • Save ptomato/7f13d17f092ab30872f5b5fe663ca507 to your computer and use it in GitHub Desktop.
Save ptomato/7f13d17f092ab30872f5b5fe663ca507 to your computer and use it in GitHub Desktop.
GetOption
// Sample Temporal code using options:
dateTime.toInstant(timeZone, { disambiguation: 'earlier' });
futureDate.difference(today, { largestUnit: 'months' });
// Sample Intl code using options:
date.toLocaleString('en-CA', { weekday: 'long' });
// ECMA-402 unfortunately specifies this:
date.toLocaleString('en-CA', 42); // => '2020-09-21, 5:20:16 p.m.'
Number.prototype.weekday = 'long';
date.toLocaleString('en-CA', 42); // => 'Monday'
// Plan:
// - Disallow this in Temporal (throw if options is not an object or undefined)
// - Make no normative changes to Intl
// - Use the new (throwing) behaviour in Intl going forward for new APIs
// - Create two abstract operations in ECMA-402, NormalizeOptionsObject and
// NormalizeOptionsObjectLegacy, as a purely editorial change
// - Move the abstract operations GetOption and NormalizeOptionsObject
// from ECMA-402 into ECMA-262 at the same time as Temporal
//
// Not asking for consensus on anything at this time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment