4 ms·
Grep your js objects
- pbiggar 14y agoLooks cool. It should be straightforward to make it avoid cycles itself, and default to infinite depth, which feels like a better default than 5.
- begriffs 14y agoActually it does mark visited objects to avoid cycles in its search. The default depth limit prevents it from taking too long on huge dom objects, but the choice of an arbitrary depth limit (of 5) does seem kind of gross. I'm open to suggestions for improvement.
- pbiggar 14y agoOh cool. The readme (at the very bottom) makes it appear like it doesn't mark visited objects.
- indubitably 14y agoif (i.match(/^[$A-Z_][0-9A-Z_$]*$/i)) { broken
- begriffs 14y agoYou're saying it is too simple of a regex to reliably match well-behaved js identifiers? Or is it broken in another way as well? What would you suggest as a better test?
- shurcooL 14y agoI would like something like this for getting fields/values from nested Go structs. Does something like that already exist, or will I have to write it?
- solox3 14y agoWouldn't it be better if the return is just a list of either the result (in the case that the value of a KV pair matches), or a reference to the result (in the case that the key of a KV pair matches)?
- oinksoft 14y agoA small thing: If you are targeting Chrome, or modern browsers in general, use Object.defineProperty(Object.prototype, 'grep', { enumerable: false, value: /* ... */ }); rather than Object.prototype.grep = /* ... */ This way, your 'grep' does not pollute for () loops.
- begriffs 14y agoFixed. Great suggestion, thank you!
- underwires 14y agonice use of jabberwocky - I think I'll switch my lorem ipsum to that.
- chadscira 14y agothis will be very useful when trying to reverse engineer something :).