javascript - ES6 tagged templates practical usability -


i understand syntax of es6 tagged templates. don't see practical usability. when better passing object parameter, settings in jquery's ajax? $.ajax('url', { /*this guy here*/ })

right see tricky syntax don't see why need/use it. found typescript team chose implement (in 1.5) before other important features. concept behind tagged string templates?

you can use tagged templates build apis more expressive regular function calls.

for example, i'm working on proof-of-concept library sql queries on js arrays:

let admins = sql`select name, id ${users}                   ${user => user.roles.indexof('admin') >= 0}` 

notice has nothing string interpolation; uses tagged templates readability. hard construct reads intuitively plain function calls - guess you'd have this:

let admins = sql("select name, id $users $filter",   { $users: users, $filter: (user) => user.roles.contains('admin') }) 

this example fun side project, think shows of benefits of tagged templates.

another example, maybe more obvious, i18n - tagged template insert locale-sensitive versions of input.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -