it is not only toString, it is every native Object.prototype like valueOf,
etc etc

for(var k in {toString:1,valueOf:1,hasOwnProperty:1})
    alert(k);

accordingly, for those methods you should check if the object
hasOwnProperty("methodName")

if($.browser.msie){
    for(var
        method =
"hasOwnProperty.isPrototypeOf.propertyIsEnumerable.toString.valueOf".split("."),
        i = 0, length = method.length;
        i < length; i++
    )
        if(object.hasOwnProperty(method[i]))
            extended[method[i]] = object[method[i]];
};

Regards





On Tue, Nov 11, 2008 at 6:16 PM, Mark Gibson <[EMAIL PROTECTED]> wrote:

>
> Mark Gibson wrote:
> > Has anyone noticed some problems with $.extend()-ing prototype, and
> > attempting to override existing methods?
> >
> > Take this example:
> >
> > var MyObj = function() {};
> >
> > $.extend(MyObj.prototype, {
> >       toString: function() { return 'Hello'; }
> > });
> >
> > var obj = new MyObj();
> > console.log(obj.toString());
> >
> > In Firefox, and other browsers, we get: 'Hello'
> > In IE (6), we get: '[object Object]'
> >
> > But, we can extend MyObj.prototype in IE these ways:
> >
> > MyObj.prototype.toString = ...
> > or,
> > MyObj.prototype['toString'] = ...
> > or,
> > MyObj.prototype = {
> >     toString: ...
> > };
> >
> > all work in IE!
> >
> > Any ideas why $.extend doesn't work?
> >
> Ok, I was a bit eager sending this, after a quick shufty through jquery.js,
> and a couple of experiments, it appears that $.extend uses a for..in loop.
>
> IE appears to not include any property called 'toString' in the loop
> regardless
> of where it comes from, and I'd guess it probably does the same with any
> other Object methods too (though I'm wasting any more time tested this).
>
> So, a warning for all, don't expect $.extend to copy 'toString' et al, and
> don't expect IE to do things as you'd expect :(
>
> Maybe a warning needs adding to the $.extend docs about this?
>
> Regards
> - Mark
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" 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/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to