Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript: how to catch any missing functions/properties for an object

Tags:

javascript

Preferences = {
 XDPI:90,
 YDPI:90,
 *:function(missing_name) {"Tell Joe he forgot to implement " + missing_name+ " property or func"}
}

Say I got an old/undocumented/minified/uglified class I want to replace with my own implementation. How could I catch all the old properties that could be missing from within my new "object" ?.

(Say there are a lot of client script (macros) used by non-technical users. I want to ease the report of missing func)

E.g if a script call Preferences.CurrentPrinter I want the Preferences object to diagnose it lacks a CurrentPrinter property without the user having to look at the console

like image 318
frenchone Avatar asked Dec 10 '25 08:12

frenchone


1 Answers

Sixth edition of ECMAScript specification introduces Proxy objects for that purpose:

http://www.ecma-international.org/ecma-262/6.0/#sec-proxy-objects

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy

But this is not widely supported yet. At the moment of writting this, only Edge and Firefox browsers do that:

http://caniuse.com/#feat=proxy

P.S. Lucky you if you read that in future and all browsers already support that :)

like image 138
Grief Avatar answered Dec 12 '25 22:12

Grief