krasimir / ktcom-comments

Comments made on https://krasimirtsonev.com/blog
MIT License
0 stars 0 forks source link

JavaScript template engine in just 20 lines #500

Open krasimir opened 4 years ago

krasimir commented 4 years ago

Article 👉 https://krasimirtsonev.com/blog/article/Javascript-template-engine-in-just-20-line


JavaScript template engine in just 20 lines

GalliumWang commented 3 years ago
freeshineit commented 1 year ago

The final implementation has errors:

1.

line.replace(/"/g, '\\\\"') + '");

this code syntaxError: missing ) after argument list

change:

line.replace(/"/g, '\\"') + '");

2. last line code to update

  return new Function(code.replace(/\\r|\\t|\\n/g, '')).apply(options);