4 ms·
Can someone please point me to the rationale behind the new toString() function?
by ahmedfromtunis 7y ago
Can someone please point me to the rationale behind the new toString() function?
- delinka 7y agoI don't know the answer to your question, but I would like to add to it to gain some clarity for myself: why not give the caller the option to have comments eliminated? An optional parameter `includeComments` bool with default `false` would provide backward compatibility while allowing those who need the comments to request them.
- deleted 7y ago[deleted]
- masklinn 7y agoRather than how complete it is, the real improvements of the proposal are: 1. it all but requires that ES-defined functions stringify to their source code. Pre-ES2019 that's implementation-defined 2. it standardises the placeholder for the case where toString can't or won't create ECMAScript code (e.g. host functions), this could otherwise be an issue as with implementation-defined placeholders subsequent updates to the standard might make the placeholder unexpectedly syntactically valid, by having the placeholder standard future proposals can easily avoid making it valid 3. the stringification should be cross-platform as the algorithm is standardised
- soulofmischief 7y agoOk that makes sense... I was really confused because that's already more or less toString()'s behavior on modern browsers, though the whitespace discrepancy is important to define.
- masklinn 7y agoThat's in part because it was fed back through browsers during the specification process.
- kevinoid 7y agoIf you are interested in all the gory details, take a look at the TC-39 proposal (especially the Goals section) and associated GitHub issues: https://tc39.es/Function-prototype-toString-revision/ https://tc39.es/Function-prototype-toString-revision/ https://github.com/tc39/Function-prototype-toString-revision/issues https://github.com/tc39/Function-prototype-toString-revision...