Skip to content

Instantly share code, notes, and snippets.

@alexcorvi
Created February 16, 2017 00:41
Show Gist options
  • Save alexcorvi/a8e3bf99020bc005d80abfcd69017894 to your computer and use it in GitHub Desktop.
Save alexcorvi/a8e3bf99020bc005d80abfcd69017894 to your computer and use it in GitHub Desktop.
JSX without react
var React = {
createElement: function (tag, attrs, children) {
var e = document.createElement(tag);
// Add attributes
for (var name in attrs) {
if (name && attrs.hasOwnProperty(name)) {
var v = attrs[name];
if (v === true) {
e.setAttribute(name, name);
} else if (v !== false && v != null) {
e.setAttribute(name, v.toString());
}
}
}
// Append children
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
e.appendChild(
child.nodeType == null ?
doc.createTextNode(child.toString()) :
child);
}
return e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment