Hi,

where is the problem? We had this discussion already very often. There
should be no problem when adding new functions to existing types.

i.e. if you want to iterante through an array you have to use:

for(var i=0; i<a.length; i++) {
    alert(a[i]);
}

With this code you will get any item inside the array, but you will
not get the .clear or .add methods.

If you use the for(item in a) statement you should have in mind that
this will not return the items in the list, it will give you all
properties of the object. And if you want you can test each item for
typeof(item) != "function".

For more details read the JavaScript reference here:

http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Statements:for...in

"Although it may be tempting to use this as a way to iterate over
Array elements, because the for...in statement iterates over
user-defined properties in addition to the array elements, if you
modify the Array object, such as adding custom properties or methods,
the for...in statement will return the name of your user-defined
properties in addition to the numeric indexes. Thus it is better to
use a traditional for loop with a numeric index when iterating over
arrays."

Regards,
Michael


On 9/28/06, Razor247 <[EMAIL PROTECTED]> wrote:
>
> We have found several ProtoTyped Javascript objects in the AjaxPro
> generated javascript that break our javascript objects. The biggest one
> is adding functions like clear() to the built in  Array object as well
> as several others using Prototype. We extended the default Array object
> to simulate a Hash table. A method added with Prototype like clear
> actually adds itself to the Array items collection without using a
> putItem due to the way JS places this new function on the object.
>
> We don't use prototype on builtin javascript objects as this is bad
> coding practice in our opinion.
>
> Your can extend javascript objects without using prototype and
> therefore not break other uses of the same builtin object. Is there
> anyway this can be changed?
>
> The way we need it
> ie. var myArray = new array()
>          myArray.clear = new function().......etc
>
> not this way
>  Array.prototype.clear = ......etc
> Any Array objected created on the page gets all the AjaxPro extensions
> to the Array
> object whether they like it or not.
>
> thanks
>
>
> >
>


-- 
Best regards | Schöne Grüße
Michael

Microsoft MVP - Most Valuable Professional
Microsoft MCAD - Certified Application Developer

http://weblogs.asp.net/mschwarz/
http://www.schwarz-interactive.de/

Skype: callto:schwarz-interactive
MSN IM: [EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Ajax.NET Professional" group.

To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]

For more options, visit this group at http://groups.google.com/group/ajaxpro

The latest downloads of Ajax.NET Professional can be found at 
http://www.ajaxpro.info/

Don't forget to read my blog at http://weblogs.asp.net/mschwarz/
-~----------~----~----~----~------~----~------~--~---

Reply via email to