[Javascript] custom extension of Array object
james
james at southspace.org
Sun Apr 24 14:52:20 CDT 2005
> > does this make sense?, the way I see it is that I make my custom object a
> > 'subclass' of the Array object.
>
>Doing exactly what you ask for is easy enough. Doing it so that the
>lenght property is changed when you add properties with a positive
>numerical identifier and so that the actual properties are cut off at
>the given point when you change the length property, that can only be
>achieved in engines that expose getter and setter interfaces.
>
> > I would gratefully receive any advice, even if it was to tell me what I am
> > trying to do is stupid!
>
>Maybe you're addressing this in the wrong way, though. Is there a
>compelling reason for you to use a custom object and inheritance
>rather than using an array to which you have added the custom
>properties? Something like this, if you want to make it a function:
>
> function CustomiseArray(arr){
> if(typeof arr=='undefined'||arr.constructor!=Array)
> arr=[];
> arr.customMethod=function(){};
> arr.customProperty='bite me!';
> return arr;
> }
>
> var
> ca=CustomiseArray();
>--
wow. finally it is sinking in! the fog clears!
More information about the Javascript
mailing list