Re: E4H and constructing DOMs

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.

Allen 

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