Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #24908
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Bind custom function to the all Function objects |
| Date | 2014-06-18 21:04 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <1420002.KozvAbkZlK@PointedEars.de> (permalink) |
| References | <98e91$539b0b89$6def49ce$21580@nntpswitch.blueworldhosting.com> <instrument-20140618014337@ram.dialup.fu-berlin.de> <instrument-20140618033308@ram.dialup.fu-berlin.de> |
Stefan Ram wrote:
> 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: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Bind custom function to the all Function objects Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2014-06-13 16:32 +0200
Re: Bind custom function to the all Function objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-13 16:56 +0200
Re: Bind custom function to the all Function objects Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2014-06-13 17:21 +0200
Re: Bind custom function to the all Function objects "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-06-13 08:39 -0700
Re: Bind custom function to the all Function objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-13 19:01 +0200
Re: Bind custom function to the all Function objects Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2014-06-13 22:41 +0200
Re: Bind custom function to the all Function objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-14 01:57 +0200
Re: Bind custom function to the all Function objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-14 15:55 +0200
Re: Bind custom function to the all Function objects Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2014-06-16 21:55 +0200
Re: Bind custom function to the all Function objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-16 23:26 +0200
Re: Bind custom function to the all Function objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-18 21:04 +0200
csiph-web