Last active
November 2, 2015 09:49
-
-
Save mgechev/1454c83c42bfd18b0e92 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function traverse(node) { | |
| return Promise.all([].slice.call(node.children).map(function (c) { | |
| return Promise.resolve(c); | |
| })) | |
| .then(function (nodes) { | |
| return Promise.all(nodes.map(traverse)) | |
| .then(function (els) { | |
| return els.reduce(function (prev, arr) { | |
| return arr.concat(prev); | |
| }, []).concat(nodes); | |
| }); | |
| }); | |
| } | |
| traverse(document.body).then(function (res) { | |
| res.map(function (e) { | |
| console.log(e.tagName); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how did this magic happens?