Created
March 5, 2015 19:42
-
-
Save ravenjohn/563a253b712f1f279167 to your computer and use it in GitHub Desktop.
Search `user` on `this`
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
var search = 'user', | |
on = this, | |
max_depth = 30, | |
found = [], | |
recurse = function (obj, from, depth) { | |
var i; | |
if (depth >= max_depth) { | |
return; | |
} | |
from = from || ''; | |
for (i in obj) { | |
if (obj[i] | |
&& obj.hasOwnProperty | |
&& obj.hasOwnProperty(i) | |
&& obj[i] !== search | |
&& !obj[i].been_here | |
&& i !== 'been_here' | |
&& obj[i] !== found | |
// uncomment the following if you're looking inside the DOM, only the global vars | |
&& obj[i] !== document | |
&& !obj[i].tagName | |
&& !obj[i].nodeName | |
) { | |
if (typeof obj[i] !== 'object') { | |
if (~(i + '').indexOf(search) || ~(obj[i] + '').indexOf(search)) { | |
var temp = {}; | |
temp[i] = obj[i]; | |
temp.from = from + '[' + i + ']'; | |
console.log(temp); | |
found.push(temp); | |
} | |
} | |
else if (typeof obj[i] === 'object' && !obj[i].been_here) { | |
obj[i].been_here = true; | |
recurse(obj[i], from + '[' + i + ']', depth++); | |
} | |
} | |
} | |
}; | |
recurse(on, '', 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment