Skip to content

Instantly share code, notes, and snippets.

@Thaina
Thaina / dom-to-json.js
Last active June 11, 2016 08:14 — forked from sstur/dom-to-json.js
Stringify DOM nodes using JSON (and revive again)
/** @param {Node|HTMLElement} node */
function toJSON(node) {
if(!node)
node = this;
var obj = { nodeType: node.nodeType };
if(node.tagName)
obj.tagName = node.tagName.toLowerCase();
else if(node.nodeName)
p_0(1 - t)^3 + 3p_1t(1 - t)^2 + 3p_2t^2(1 - t) + p_3t^3
\\
p_0(1 - 3t + 3t^2 - t^3)
+ 3p_1(t - 2t^2 + t^3)
+ 3p_2(t^2 - t^3)
+ p_3t^3
\\
t^3(p_3 - 3p_2 + 3p_1 - p_0)
+ t^23(p_2 - 2p_1 + p_0)
+ t3(p_1 - p_0) + p_0