Opened 4 years ago

Closed 4 years ago

#18476 closed defect (wontfix)

dojo/_base/array has [almost completely] unused variable, "u"

Reported by: gitgrimbo Owned by:
Priority: undecided Milestone: tbd
Component: Core Version: 1.10.4
Keywords: Cc:
Blocked By: Blocking:

Description

I was copying the dojo/_base/array code to implement find/findLast using a predicate (instead of a value to compare), when I noticed my code didn't work as it was referencing a variable, "u", that didn't exist.

It didn't exist as I hadn't copied it across, but I'm not sure it's needed in the original code. The value is never written to, and so remains undefined.

Code

https://github.com/dojo/dojo/blob/1.10.4/_base/array.js#L6

Declaration:

	var cache = {}, u;

https://github.com/dojo/dojo/blob/1.10.4/_base/array.js#L53

'Use'. Comparison will always be false unless from === undefined. If this is supposed to be a test for undefined, then there are more obvious ways to do this.

			if(from === u){
				i = up ? lOver : l + uOver;
			}else{

Change History (2)

comment:1 Changed 4 years ago by gitgrimbo

Just realised that u probably is a shortcut for undefined after all!

Ignore my ticket unless you think that because it tricked a simpleton like myself that the code could be made more obvious :)

comment:2 Changed 4 years ago by bill

Resolution: wontfix
Status: newclosed

OK, I guess we should close this. I agree the variable name is confusing. If you are wondering why there's a variable at all, IIRC it's to protect against the unlikely case that someone redefines the global "undefined". Sounds paranoid and ineffective to me but anyway that's probably why the code is written that way.

Note: See TracTickets for help on using tickets.