Nickolay Ponomarev wrote:
On Jan 23, 12:59 am, Richard Cornford wrote:
>Nickolay Ponomarev wrote:<snip>
>>As to what's wrong with new Function(),
a) it gives a bad example
You should not expect anyone to give much credence to an argument that says
"it gives a bad example" is you do not state what it is that it gives an
example of, or what it is that is bad about it.
I said what's bad about it right below.
So that was that strings are not internally syntax highlighted and that
it might be difficult to spot code errors in such strings. Both of
which are largely mitigated if the contents of function body strings
used with the Function constructor are limited in their internal
complexity. Certainly not enough to justify labelling their use as
giving "a bad example".
The reason I started with (a)
"it gives a bad example" is hardly a reason, as it does not state what
that bad example is, or what it bad about it.
is that this is what I'm mainly concerned
about. I would expect clj FAQ to give good examples.
It is not necessarily possible to regard any simple example as good or
bad. You have concerned yourself with the explicit declaration of
variables (in a nearby thread), but what is to stop someone seeing an
example of such and making a bad application of a declaration such as
features in the second example of code in what follows?
>We even have browser's like Mozilla/Gecko spitting out spurious and bogus
"warnings"
Any examples? (I know this is off-topic, but since I'm a bit familiar
with moz and never heard of these, you got me interested)
Given the code:-
if(window.clipb oardData){
alert('clipboar d')
}
Mozilla 1.6 (for no other reason than it is the Mozilla version on this
machine) outputs the warning:-
"Warning: reference to undefined property window.clipboar dData"
- while with:-
if((typeof window.clipboar dData) == 'object'){
alert('maybe clipboard, or null')
}
- it does not. In the case of the first code the property accessor -
window.clipboar dData - is evaluated into a Reference type, a value
retrieved using that Reference type and that value type-converted to
boolean. In the second case the property accessor -
window.clipboar dData - is evaluated into a Reference type, a value
retrieved using that Reference type and then the type of the value used
to determine one of a set of string values, which is then compared with
a string literal to produce a boolean result.
If any point in those processes can be ladled as a "reference to
undefined property" that should occur in the process of using the
Reference type to retrieve a value (as the creation of the Reference
type has no interest in whether any object assigned to its 'base'
property has a property with the name used as its 'propertyName'
property). Both of the examples above use the same Reference type to
retrieve the same value, so if one produces a warning and the other
does not then either the warning it spurious when it is produced in
the first case or its absence is bogus in the second.
Given the code:-
function testFunc(param) {
var param; // This is a "bad" application of the otherwise "good"
// declaration of local variables.
}
Mozilla outputs the warning:-
"Warning: variable param hides argument"
- and that is an absolute lie. ECMA 262 is very clear about how such
code should be handled (Section 10.1.3) and not only does the - var
param; - not "hide" the - param - formal parameter it is actually
specified as doing nothing (that is, the local variable declaration
does not replace the pre-existing property of the Variable object with
the name - param -, and it does not modify its value). It would be
possible for the warning to express the pointlessness of declaring a
local variable with the same name as a function's formal parameter, but
outputting a factually false statement instead is wrong, and
undermines the credibility of all the warnings generated on the system.
>>Why does http://www.jibbering.com/faq/ uses new Function
constructor instead of function expressions (function(...) { ... })
when defining new functions?
Mostly because much of it was written half a decade ago when anything else
would not have been cross-browser. It has remained because it a. it still
works fine, b. no compelling argument has ever been presented for changing
it (leaving it largely a matter of taste as to whether it gets changed).
Are you re-ordering the material you are quoting (without stating as
much)? That would generally be regarded as disingenuous.
You could save me and yourself some time by only posting this. You
answered my question.
<snip>
I was interested in whether you would present any compelling arguments
for changing the FAQ. You have not.
Richard.