Skip to content

Instantly share code, notes, and snippets.

@monolithed
Forked from alexcorvi/file.js
Created April 24, 2017 07:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monolithed/036c40895bcf7d4893ff7779a89868ca to your computer and use it in GitHub Desktop.
Save monolithed/036c40895bcf7d4893ff7779a89868ca 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