5 ms·
https://jsfiddle.net/yurctL2c/3/ https://jsfiddle.net/yurctL2c/3/
by Schampu 9y ago
https://jsfiddle.net/yurctL2c/3/ https://jsfiddle.net/yurctL2c/3/
- z3t4 9y agoI mean like misspelled properties eg. obj.x edit: I figured it out myself, just replace ASSIGN with MEMBER ! Awesome! I've been thinking of how to do this statically for a while now, but dynamically is good enough, as it still will be able to point out the bug before you even start debugging. I think this is game changing and will make things like Typescript feel like stone-age. I'm currently working on an editor/IDE for JavaScript and I can just add a check-box like "static typing" and you'll get warnings every time a variable or function parameter change type.
- ldd 9y agoproxies can do this relatively easily.[0] Here's a minimal fiddle doing just that: https://jsfiddle.net/6v82dj01/ https://jsfiddle.net/6v82dj01/ As for actual implementations, I used it in a small analyzer for RPG Maker MV plugins[1] that roughly does what you want with very little actual code[2]. [0]: http://exploringjs.com/es6/ch_proxies.html#sec_proxies-explained http://exploringjs.com/es6/ch_proxies.html#sec_proxies-expla... [1]: https://github.com/ldd/plugin-analyzer https://github.com/ldd/plugin-analyzer [2]:https://github.com/ldd/plugin-analyzer/blob/master/plugin-analyzer.js#L22-L49 https://github.com/ldd/plugin-analyzer/blob/master/plugin-an...
- z3t4 9y agoyes, but you have to manually select which objects to watch, eg in your script, it goes through the window object and adds the Proxy observer to a set of classes. But Iroh doesn't use Proxies. With Iroh you can trigger an event for example "Iroh.MEMBER" and check if the property is undefined.
- ldd 9y agoI only observe certain classes because observing anything and everything is not convenient. Nothing prevents you from doing `window = new Proxy(window, handler)` (or more generally, to Proxy the global object) where the handler replaces anything with a Proxied version of it either once a trap triggers (yu-gi-oh style) or immediately. Then again, I did not write the specification for `Proxy` and Iroh is cool. It probably has plenty of use-cases where Proxy would not do a good job. I'm just showing what we have right now.
- CapacitorSet 9y agoMisspelled properties? There's a module for that, using the same underlying technology: https://github.com/mathiasbynens/tpyo https://github.com/mathiasbynens/tpyo
- vladimir-y 9y agoYou might want to try Typescript.