(no subject)
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

(no subject)

From: Thomas 'PointedEars' Lahn <PointedEars@web.de>
Date: Tue Jul 19 2005 - 21:03:35 CEST

VK wrote:

Who wrote that? Please provide proper attribution.
vvvvvvvvvvvvvvv
>> > <sample>
>> > var arrayObject = new Array();
>> > alert(arrayObject.slice) // native code
>> > arrayObject = document.getElementsByTagName('P');
>> > alert(arrayObject.slice) // undefined !
>>
>> The getElementsByTagName method is defined as returning an object
>> implementing the NodeList interface. The NodeList interface defines no
>> slice method.
>
> Exactly my point. As getElementsByTagName() returns an HTMLCollection,
> JavaScript automatically converts arrayObject from Array type to
> HTMLCollection type to accomodate new data structure.

No, "it" does no such thing at all. What happens is that the reference to
the newly created Array object that is stored in the `arrayObject' variable
is replaced by a reference to the HTMLCollection object that the W3C DOM
method returns. Since the HTMLCollection interface does not provide a
`slice' method, of course `arrayObject.slice' yields `undefined' as the
object referred to does not have such a method. (Richard already explained
that to you.) See ECMAScript 3, subsection 11.13.1.

It is then likely, if there are no further references to the Array object,
that the Garbage Collector will mark the unreferenced Array object for
deletion, and therefore the memory allocated for that object will
eventually be freed.

>> Javascript never casts objects.
> myObject.toString();
> The most primitive type of explicit casting I'm sure you used a while
> already.

myObject.toString() performs implicit type conversion of `myObject' by
returning a string value; for non-core objects, the `toString()' method
inherited from the Object prototype may be redefined to accomodate the
features of the calling object. This is *not* the same as type casting
as implemented in class-based OOP languages like Java. See ECMAScript 3,
subsections 15.2.4.2, 15.3.4.2, 15.4.4.2, 15.5.4.2, 15.6.4.2, 15.7.4.2,
15.9.5.2, 15.10.6.2 and 15.11.4.4, and e.g.
<http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.5>

>> The language itself only uses one type of object, and that object is
>> totally dynamic so any object may implement any interface, and different
>> interfaces at different times.
>
> This description fits to any existing OOP language.

No it does not. E.g. classes in Java are of different data types:
<http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.3>

> > Thinking in terms of 'casting' in a language that does not have classes
> > is likely to be counterproductive.
>
> Class is simply a factory of objects with predefined behaviors.
> Each object in JavaScript has its constructor property reffering
> to its creator.

There was not even a `constructor' property defined before JavaScript
1.1, JScript 2.0 and ECMAScript although JS was object-oriented and had
constructors from the start. And the `constructor' property is not
read-only.

> To avoid the word "class" we could call it "object
> constructor" but it would be a bizarre term.

No. In JavaScript 1.x/JScript up to 5.x/ECMAScript up to 3, objects
inherit from each other. In Java and other class-based OOP languages,
classes inherit from each other and an object is an instance of a class.

PointedEars
Received on Tue Oct 18 02:58:22 2005