Tag Functions

JS
S
JavaScript

Simple example of the syntactic sugar of tag functions (template strings).

1const telemetry = 'feed1';
2const lastValue = 44.4;
3function tagFunction(sourceArr,telemetry,val){
4  console.log(sourceArr[0] + telemetry + sourceArr[1] + val + sourceArr[2]);
5}
6tagFunction`Test ${telemetry} singal was ${lastValue}`;
7
8// Iteration 
9const data = [
10{ telemetry: 'feed2', value: 11.1 },
11{ telemetry: 'feed3', value: 17.3 }
12]
13data.forEach((p) => {
14   tagFunction`Test ${telemetry} singal was ${lastValue}`;
15});

Created on 12/4/2017