Skip to content

Instantly share code, notes, and snippets.

@thejefflarson
Created March 16, 2016 17:02
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 thejefflarson/5f13160fe089ec68e8a7 to your computer and use it in GitHub Desktop.
Save thejefflarson/5f13160fe089ec68e8a7 to your computer and use it in GitHub Desktop.
// compare to: https://github.com/dominictarr/hyperscript/blob/master/index.js (lol)
var e = function(/* tag, attrs, text, children...*/ ) {
var args = [].slice.call(arguments);
var tag = args.shift() || 'div';
var atts = args.shift() || {};
var text = args.shift() || '';
var kids = args;
var el = document.createElement(tag);
Object.keys(atts).forEach(function(k) {
el.setAttribute(k, atts[k]);
});
el.appendChild(document.createTextNode(text));
kids.forEach(function(e) {
el.appendChild(e);
});
return el;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment