Inline rendering with document​.currentScript

Inline rendering with document​.currentScript

Lean Rada describes a neat trick that takes advantage of the document.currentScript property. You can use that to drop in a tiny inline element that replaces itself when the page loads:

The year is 

If you define a shortcut function like this:

$=(...n)=>document.currentScript.replaceWith(...n)

You get a tiny template language:

The year is 

Tags: javascript

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论