Bug Tracker

Ticket #5554 (closed feature: wontfix)

Opened 5 years ago

Last modified 5 years ago

length expando overwrite

Reported by: dbjdbj Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: Cc:
Blocking: Blocked by:

Description

We know that length expando is overwritten by certain browsers, in certain situations. Maybe a new utility function should be added to the core.js ?

safeLength : function ( obj ) {

  if ( jQuery.isArray(obj)) return obj.length ;
  
  var j = 0; while ( obj[j++] ) ; return j-1 ;

}

This could/should be used from merge(), grep(), map() and each()

--DBJ

Change History

comment:1 Changed 5 years ago by dbjdbj

I am thinking ... maybe I have jumped on this one too eraly? I think that each() will solve safely "length expando overwrite" because it does objects (ie non-arrays) with for/in loop anyway? that is it does not use length. So maybe each() as it is, does the job? the solution is to make grep(), merge(), map() etc, to use each().

safeLength() might stay, but I do not see where it could be used inside jQuery ? There must be some use for it ?

--DBJ

comment:2 Changed 5 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

This seems more appropriate for the jQuery-dev group since it isn't reporting a bug.

comment:3 Changed 5 years ago by dbjdbj

  • Status changed from closed to reopened
  • Resolution invalid deleted

I admit I "made it" into bug to gain attention. Please look into my fork on GITHUB (user: DBJDBJ ) I managed to streamline each() using the above and to streamline merge(), grep(), makeArray() to use each(). I have done testing. This needs to be tested/seen by someone from the core team. Looks ok and obvious, but is a non-trivial change in the core.

Thanks: Dusan

comment:4 Changed 5 years ago by john

  • Status changed from reopened to closed
  • Resolution set to wontfix
  • Component changed from unfilled to core
  • Type changed from bug to feature

This isn't really something that we need in core. We just do looping in a particular way to avoid the problem outright.

Note: See TracTickets for help on using tickets.