Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Bind custom function to the all Function objects Date: Wed, 18 Jun 2014 21:04:17 +0200 Organization: PointedEars Software (PES) Lines: 104 Message-ID: <1420002.KozvAbkZlK@PointedEars.de> References: <98e91$539b0b89$6def49ce$21580@nntpswitch.blueworldhosting.com> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1403118265 5785 eJwFwQcBwEAIBDBLwDGKHNb7l9DE4OwT6uZqz54389bASGm5615zSOl8GJmUJIHp3oQXLvEDIJgRFw== (18 Jun 2014 19:04:25 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Wed, 18 Jun 2014 19:04:25 +0000 (UTC) User-Agent: KNode/4.12.4 X-User-ID: eJwFwYkBwEAEBMCWnGdRDkL/JWTGBA/jCoPa2RWMg/UbKwVJMHusvAsnn4pb8cGqJlI9t5qHUtB8zUIzPzALFN4= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. ram@zedat.fu-berlin.de (Stefan Ram) writes: >>"use strict"; > > The next version instruments more different functions. > > It does not try to instrument the console object. As this > is used for debugging purposes within the instrumented > functions, instrumenting it might cause infinite recursion. But is is augmenting the object referred to by “console.log”, a callable property of a host object. That is a Really Bad Idea. (And for what?) > "use strict"; > > const global = this; > > function main() > { "use strict"; If the global code is strict code, the function code is automatically strict code (strict mode cannot be undone for security reasons). So this declaration is unnecessary. > […] > const enumerate = function( path, object ) > { "use strict"; > if( typeof global.Object.getOwnPropertyNames === "function" ) ^^^^^^ This *closure* is unnecessary if you do not amok-code and start declaring “Object” locally (or expect this from others; but the way you write code, I can see how that expectation might easily come to your mind). There is also no performance advantage in this because the scope chain needs to be consulted either way. There is a clear performance disadvantage because an extra property lookup for “global” needs to take place. An explicit reference to the global object should only be used if absolutely necessary. Also it makes sense to cache references locally, because the scope chain is shorter then, which increases runtime efficiency. > { const key = global.Object.getOwnPropertyNames( object ); > const keyLength = key.length; > for( let i = 0; i < keyLength; ++i ) The “let” keyword is not specified in the current standard, ECMAScript 5.1 Edition. (Neither is the “const” keyword.) AFAIK, it is supported by Mozilla JavaScript only; earlier versions only supported it if your declared version 1.7 by “type” attribute of the “script” element. Code posted here should be written according to the standard (Ed. 3 and later), for a reasonable level of compatibility. Implementation-specific or experimental features should be either avoided or clearly documented as such. > […] > global.Object.getOwnPropertyNames.wasInstrumented20140618032449 = > global.Object.wasInstrumented20140618032449 = > global.Date.wasInstrumented20140618032449 = > global.Number.wasInstrumented20140618032449 = > global.String.wasInstrumented20140618032449 = > global.Boolean.wasInstrumented20140618032449 = > global.Function.wasInstrumented20140618032449 = > global.console.log.wasInstrumented20140618032449 = I do not think it is a good idea to refer to “console” as property of the global object of one particular global execution context. Instead of copy-pasting the ID, one should reuse a constant-like value like this: Object.getOwnPropertyNames[INSTRUMENTAL_PROPERTY] = true; I find it curious that you appear to be using the not backwards-compatible “const” keyword for anything but true constants. Finally, your code style is still hard to read, to say the least. For example, using a loop is indicated here instead of multiple nested assignments: for (var a = [["Object", "getOwnPropertyName"], "Object", "Date", "Number", "String", "Boolean", "Function"], i = a.length; i--;) { var p = a[i]; if (Array.isArray(p)) { global[p[0]][p[1]][INSTRUMENTED_PROPERTY] = true; } else { global[p][INSTRUMENTED_PROPERTY] = true; } } The very least you should do is to indent nested assignments. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.