Java script Dude wrote:
^^^^^^^^^^^^^^^^
Even your nickname talks volumes. Java != JavaScript. (Which includes,
but is not limited to, that it is not necessary to create String objects
as you did before.)
Unfortunately, in the corporate world, IE is a fact that cannot be
avoided. MS has sucessfully created issues for all of us JS hackers
You are not a JS hacker. You are a script-kiddie.
and we must work within their domain.
No, "we" must not. And "we" need not to and still be successful. And,
IE is not even the point here.
What you have still not understood is that JScript as implemented in IE
is an ECMAScript implementation, a prototype-based programming language.
JavaScript as supported since NN2, and now in Mozilla/5.0, is another
ECMAScript implementation.
DOM objects are host objects, they are not part of either language
(unfortunately that distinction was made in JavaScript not before version
1.4) and do not need to implement many ECMAScript features as specified.
That is not a flaw, the "host object exception" is instead well specified
in ECMAScript and especially the IE DOM honors that very much (allowing
host object methods to return typeof "object" and allowing collections
like `document.all' to be used like methods, for example.)
Allowing a peculiarity of one DOM/UA to define your programming style is
probably the greatest sign of incompetence you could possibly display.
If you use a objects method as the original example suggests, you will
have to do the following statement for testing if object is an array:
if(o && o.getClassOf && o.getClassOf() == "Array"){...
With my example:
if(oGetClassOf(o)=="Array"){...
Current ECMAScript implementations in user agents (UAs) have no classes;
the only production-ready ECMAScript implementation supporting class-based
inheritance is JScript.NET (JScript 7.0) for ASP.NET on IIS (server-side).
Array objects are not host objects as HTMLDivElement objects are, they
are core objects. Therefore, for Array objects, a simple
if (o instanceof Array)
(since JavaScript 1.5 [Mozilla/5.0], JScript 5.0 [IE5], ECMAScript 3) or
if (o.constructor == Array)
(since JavaScript 1.1 [NN3], JScript 2.0 [IIS3/IE3], ECMAScript 1) suffices
for this test. There is no unreliable RegExp parsing necessary at all.
I'd say this my example is much more useful for JavaScript as it is
short and consice and will work in all browsers.
In all browsers that you have tested with, perhaps. Which are most
certainly not many.
The only disadvantage is the loss of JS namespace.
You are relying merely on the implementation of the toString() method of
Function objects that is _known_ to differ between UAs, which is the main
disadvantage. Relying on it can be considered harmful. The method may
be nice for educational purposes, it is certainly not for practical use.
Another advantage of using a standalone function is that the function
can be tuned to be immune to null (undefined) attributes.
null != undefined, and attributes not defined in the DOM have the value
of `undefined' in all known DOMs, which can be easily tested for:
typeof foo.attribute != "undefined"
or
foo.attribute != undefined
with the provision for the latter that the `undefined' property of the
Global Object may have been user-defined before (sounds strange but is so):
// global context
var undefined = undefined;
But probably you did not even refer to attributes of elements but to
"attributes" of objects. FYI: In ECMAScript implementations, objects
have _properties_. And it is not possible with your method to test if
a property is undefined or its value is `undefined' (which is the same
on read access) as `undefined' has no properties, not even `constructor'.
See previous discussions.
I was not writing on how to write standards based html. I was writing a
minimal amount of html to get the JS to run. Get a grip!
You were talking nonsense before, and you are talking nonsense again.
Script code used in not Valid markup is not likely to work as supposed,
being non-interoperable per se. Invalid examples are useless.
No - See above example. Short an consise is the key to good JS.
Hello?
alert(document.getElementById('divTest').tagName)); // div
as opposed to
alert(oGetClassOf(document.getElementById('divTest'))));
which will probably not work in IE (HTMLDivElement objects should have
no constructor property there if they do not inherit from Object), and
which will force time-consuming method calls and RegExp replacement
that will probably have no usable result all, that is 'Unknown', which
is not true. Big time.
And in IE you could even do
alert(divTest.tagName);
(as the IE-DOM makes named/IDed elements, spoiling the global namespace).
So far for conciseness.
If I am missing something maybe you could give some insight on how to
best continue a thread that is closed.
You have not even understood what medium you are really using, what
Usenet is. "continue a thread that is _closed_". YMMD again.
<URL:
http://en.wikipedia.org/wiki/Usenet>
PointedEars, amused