W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2013

Re: E4H and constructing DOMs

From: Allen Wirfs-Brock <allen@wirfs-brock.com>
Date: Sat, 9 Mar 2013 17:15:19 -0800
Cc: Ojan Vafai <ojan@chromium.org>, Adam Barth <w3c@adambarth.com>, Domenic Denicola <domenic@domenicdenicola.com>, Jonas Sicking <jonas@sicking.cc>, Anne van Kesteren <annevk@annevk.nl>, Rick Waldron <waldron.rick@gmail.com>, Adam Klein <adamk@chromium.org>, Ian Hickson <ian@hixie.ch>, "rafaelw@chromium.org" <rafaelw@chromium.org>, Alex Russell <slightlyoff@chromium.org>, "public-script-coord@w3.org" <public-script-coord@w3.org>, "Mark S. Miller" <erights@google.com>
Message-Id: <F88D1F91-9AA1-441D-847D-DEC2B483E26E@wirfs-brock.com>
To: Brendan Eich <brendan@secure.meer.net>

On Mar 9, 2013, at 3:59 PM, Brendan Eich wrote:

> Ojan Vafai wrote:
>> I would imagine that some folks on this list would be resistant to having the default handler be one that produces a DOM instead of a string. Could we have a browser-provided html handler that does E4H style parsing and not have a default handler at all? That way, the simplest code path for developers is to use the browser-provided handler and they have to go out of their way to do something else, but we still leave the door open for other use-cases/handlers (e.g. contextually parsed html).
>> header.appendChild(`<h1>Welcome ${ firstName } ${ lastName }!</h1>`); // parse error
>> header.appendChild(html`<h1>Welcome ${ firstName } ${ lastName }!</h1>`); // E4H style parsing
>> header.appendChild(myspecialhtmlparser`<h1>Welcome ${ firstName } ${ lastName }!</h1>`); // template strings as currently proposed
>> The only thing we lose here I think is an easy way to do multiline strings in JS.
> This is a productive suggestion. Thanks -- we will discuss it at next week's Ecma TC39 meeting, I've added it to the agenda.

and a plausible name for the tag handler that only does simple string interpolation is: String 

In other words it is just an overload on the String constructor (assuming we make sure that callsite objects are recognizable) and you would use it like:
   console.log(String`Welcome ${ firstName } ${ lastName }!`);

However, I'm not sure that this is much more than a feel good fix for this issue.  We still have to educate developers that that must say:
     header.appendChild(html`<h1>Welcome ${ firstName } ${ lastName }!</h1>`);
rather than
     header.innerHTML("<h1>Welcome "+firstName+" "+ lastName+"</h1>");

Once somebody has learned that, they know not to use an untagged string template so they really aren't a hazard for them.  If they haven't learned that they probably are still passing + concatenation to innerHTML calls.

Received on Sunday, 10 March 2013 01:15:56 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:08 UTC