Last active August 29, 2015 14:19
Save zenparsing/9ff3036b6eb15fa436e4 to your computer and use it in GitHub Desktop.
Definitely Maybe with Proxy
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 const unwrapSymbol = Symbol(); function Definitely(x) { if (x == null || !(unwrapSymbol in x)) return x; return x[unwrapSymbol]; } const Nothing = new Proxy(Object.seal(function() {}), { get(target, key) { return key === unwrapSymbol ? void 0 : Nothing }, set() {}, has() { return true }, apply() { return Nothing }, construct() { return Nothing }, }); const maybeHandler = { get(target, key) { return key === unwrapSymbol ? target : Maybe(target[key]) }, has(target, key) { return key === unwrapSymbol || key in target }, apply(target, thisArg, argumentList) { if (thisArg !== Nothing) thisArg = Definitely(thisArg); return Maybe(target.apply(thisArg, argumentList)); }, }; function Maybe(x) { return x === Nothing || x == null ? Nothing : new Proxy(Object(x), maybeHandler); } // alert(Definitely(Maybe(self).document.scripts[0].parentNode.nodeName)) // alert(Definitely(Maybe(self).document.querySelectorAll("div").length))You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4