Created
July 6, 2016 16:09
-
-
Save edwardgalligan/3e25c984cb904e46af8581bfe2a10544 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* document.createElement re-implemented with a fluid interface | |
* | |
* Note: This will break lots of stuff. Don't use it. | |
* Note: This could be done by altering Element.prototype but that would break even more stuff | |
* | |
* Usage example: | |
* document.body.appendChild( | |
* document | |
* .createElement('a') | |
* .setAttribute('href', '#success') | |
* .appendChild( | |
* document.createTextNode('Testing...') | |
* ) | |
* ) | |
*/ | |
document.createElement = (function() { | |
var createElement = document.createElement | |
return function(el) { | |
var node = createElement.call(document, el) | |
node.setAttribute = function(key, val) { | |
Element.prototype.setAttribute.call(node, key, val) | |
return node | |
} | |
node.appendChild = function(kid) { | |
Element.prototype.appendChild.call(node, kid) | |
return node | |
} | |
return node | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment