On Sep 26, 1:29 am, Richard Cornford wrote:
I think you meant "portrays" not "betrays". Am I right?
No, "betrays" says exactly what I intended to say.
That analysis would be right if they'd used ||, but they
used &&.
No, that analysis is correct because it uses &&.
I provided analysis of the problem on my site.
That is not what I would call it. It is a pity that you choose to
publish such things without first having them checked by someone who
knows this subject.
The problem is that this function returns true for
objects (of any type) that contain
"function" in the toString result.
It also may return false for object that are functions. The author is
clearly unsure about what it is that is being tested for, and so has no
criteria for identifying an effective test for that (if one exists).
(!!fn )....................falses are out.
A pointless test if the subject is not expected to potentially be a
value that has falseness.
(typeof fn != "string")....string values are out
A pointless test if the subject is not expected to potentially be a
string primitive.
(!fn.nodeName).............things with a truthy nodeName are out.
A pointless test if the subject is not expected to potentially be an
object with a true nodeName property. An expected characteristic of DOM
elements.
(fn.constructor != Array)..Arrays in same frame are out.
A pointless test if the subject is not expected to potentially be an
Array.
(/function/i.test( fn + "" ).anything else left can get
through, it just has to say "function".
So in what sense is my "analysis" not correct? "It looks like the
subject of the test is expected to be any of a javascript function
(unwisely tested), a siring primitive, a DOM element and Array or a
value with falseness".
It's not safe, but it's indicative of the problem of
typechecking in js.
Dojo has similar stuff.
The dojo version of isFunction is nearly as bad as it will also return
true for non-callable objects. Again the authors appear to be uncertain
of what it is they are testing for.
They claim that some built-in functions don't
return "function" for typeof.
They can claim anything they like, but if it were a true statement they
could state the environment in which this was the case and show a test
case that proves the point (or shows where their misconceptions lie).
Without that, and judging their competence by the code in dojo, I would
not trust them to have made an accurate analysis.
I have been unable to prove that
statement true.
<snip>
You should not need to. The person making the claim is the one
responsible for demonstrating it.
No. typeof fn != 'string' should *always* be true.
Yes, it looks like I omitted a "not" between "being" and "true". One of
the consequences of rushing to get it posted before going to work on a
week day.
or its having a - nodeName -
You're confused by thinking ||. The function uses &&
No I am not. To get a true result with the logical AND operation test
every individual sub-expression needs to evaluate to true.
Anyway, typechecking is an issue
Not really. Once you get used to properly employing a loosely typed
language it rapidly becomes a non-issue, and such testing is relegated
to the feature testing role alone. Hence my assertion that the test
betrays poor design. Before someone has the experience to cope with
loose typing they will be struggling to identify the types of things
from a position of being totally in the dark. This results in such
testing functions being passed almost anything at all, and so having to
jump through hoops applying tests that really should never be necessary.
You know, it might not be very good code, but I think John
might be creative.
Being "creative", of itself, is of little significance. Masses of
dubiously code and all of those half-ass hacks were 'created' by
someone.
To be usefully creative it is necessary to first formulate a clear
notion of what it is that is to be achieved. It is evidence of this
clarity of comprehension that is absent from the testing code. Hence my
assertion that the test betrays poor design. Before someone has the
experience to cope with loose typing they will be struggling to identify
the types of things from a position of being totally in the dark. This
results in such testing functions being passed almost anything at all,
and so having to jump through hoops applying tests that really should
never be necessary.
He's interested in these things, so improvement is
inevitable.
That may be likely, but not inevitable. It appears that becoming
satisfied with what you have done can seriously inhibit an ability to
improve.
What is not conforming in Prototype?
<snip>
ECMS 262 provides an EvalError that is to be thrown when the - eval -
function is called indirectly (in any way other than as - eval(
seomthing ); - ). It then gives implementations the option of not
throwing that exception. ECMAScript conforming code has no choice but
assume the worst case (that the exception will be thrown), while
Prototype.js makes the assumption that no implications will (ever) throw
that exception. Thus it sacrifices ECMAScript compatibility (and so all
hope of its ever being cross-browser) and ends up being dependent upon a
limited set of known (current) implications where the exception can be
observed not to be thrown.
Richard.