document.currentScript を使ったインラインレンダリング
document.currentScript を使ったインラインレンダリング Lean Rada は、document.currentScript プロパティを活用した巧妙なテクニックを紹介しています。これを使えば、ページ読み込み時に自身を置き換える小さなインライン <script> 要素を挿入できます: 年は <script> document.currentScript.replaceWith( new Date().getFullYear())</script> です。さらに、次のようなショートカット関数を定義すれば: $=(...n)=>document.currentScript.replaceWith(...n) すると、非常に簡潔なテンプレート言語が使えます: 年は <script>$(new Date().getFullYear())</script> です。タグ:javascript