返回资讯中心
外部精选
ai-models
#LLM#工程实践#javascript

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…

Simon Willison2026/10/17 · 9 天前1 分钟阅读

以下正文同步自 Simon Willison,版权归原站所有,已转换为易读排版。

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 
document.currentScript.replaceWith(
  new Date().getFullYear())

If you define a shortcut function like this:

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

You get a tiny template language:

The year is $(new Date().getFullYear())

Tags: javascript

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →