Skip to content

ProtoString template() Method

Seth Clydesdale edited this page Jun 3, 2015 · 2 revisions

<< Back to Polyfill Methods

Example

The string variable name should be the same as the object key.

'Hello ${name}, would you like some ${food}?'.template({
  name : 'Seth',
  food : 'coffee'
});
// returns 'Hello Seth, would you like some coffee?'

Description

The template method aims to give you similar functionality to the template strings in ES6. Inline string variables are defined using ${VAR}, where VAR is the name of your variable. An object passed as the parameter defines all the variable data.

Syntax

String.template(data);

Parameters

Parameter Description
data An Object which contains the variable data for the string. Object keys should be spelt the same as your string variables.
Clone this wiki locally