Skip to content

Instantly share code, notes, and snippets.

@laduke
Last active March 2, 2019 00:32
Show Gist options
  • Save laduke/bc9c85823459e26f3dee11dfdbb294e2 to your computer and use it in GitHub Desktop.
Save laduke/bc9c85823459e26f3dee11dfdbb294e2 to your computer and use it in GitHub Desktop.
function h(tag, as, xs) {
var attrs = Object.entries(as).map(([k, v]) => ` ${k}="${v}"`);
return `<${tag}${attrs}>${xs.join("")}</${tag}>`;
}
console.log(
h("div", { id: "foo" }, [
h("p", { class: "big" }, ["hi", h("p", {}, ["3"])]),
h("p", {}, ["bye"])
])
);
/*
<div id="foo">
<p class="big">hi
<p>3</p>
</p>
<p>bye</p>
</div>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment