Skip to content

Instantly share code, notes, and snippets.

@johnjbarton
Created August 7, 2012 16:55

Revisions

  1. johnjbarton created this gist Aug 7, 2012.
    19 changes: 19 additions & 0 deletions backbacktick.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    // Comparing some of the use-cases for 'quasi-literals' aka string templates to normal functions and strings
    // http://wiki.ecmascript.org/doku.php?id=harmony:quasis#syntax

    x`foo${bar}baz`
    // vs
    x('foo',bar,'baz');

    // http://wiki.ecmascript.org/doku.php?id=harmony:quasis#secure_content_generation

    safehtml`<a href="${url}?q=${query}" onclick=alert(${message}) style="color: ${color}">${message}</a>`
    // vs
    safehtml('<a href="',url,'?q=',query,'" onclick=alert(', message,') style="color: ',color,'>',message,'</a>');

    // http://wiki.ecmascript.org/doku.php?id=harmony:quasis#text_l10n

    msg`Welcome to ${siteName}, you are visitor number ${visitorNumber}!`
    // vs
    msg('Welcome to ',siteName,', you are visitor number ',visitorNumber,'!');