Those two helper functions are variants of System.prototype.write, different only in that they pass different sets of JQuery function names to doWrite(). I found myself wanting ways of replacing content wholesale or adding nodes into an element in a way that was square with everything doWrite() does, so this is the easiest way to get that working in a modular way.
System.prototype.writeInto() calls doWrite() passing the name of the JQuery append() function. This means that unlike System.prototype.write(), when a selector is specified, new content is written as a new child node at the end of the matched element, rather than as a new sibling node after the matched element.
System.prototype.replaceWith() calls doWrite() passing the name of the JQuery replaceWith() function. The result is that either the matched element, or the entire situation is replaced with the given content. I wrote this to use it exclusively with a selector, and I'm not sure the latter is safe; maybe this should throw an error if it's called without a selector, or instead it should default to selecting the first/last child node of the situation?
Those two helper functions are variants of System.prototype.write, different only in that they pass different sets of JQuery function names to
doWrite()
. I found myself wanting ways of replacing content wholesale or adding nodes into an element in a way that was square with everythingdoWrite()
does, so this is the easiest way to get that working in a modular way.System.prototype.writeInto()
callsdoWrite()
passing the name of the JQueryappend()
function. This means that unlikeSystem.prototype.write()
, when a selector is specified, new content is written as a new child node at the end of the matched element, rather than as a new sibling node after the matched element.System.prototype.replaceWith()
callsdoWrite()
passing the name of the JQueryreplaceWith()
function. The result is that either the matched element, or the entire situation is replaced with the given content. I wrote this to use it exclusively with a selector, and I'm not sure the latter is safe; maybe this should throw an error if it's called without a selector, or instead it should default to selecting the first/last child node of the situation?