`_.where` shouldn't use `_.isEmpty` #838

Closed
jdalton opened this Issue Oct 24, 2012 · 5 comments

Projects

None yet

2 participants

@jdalton
jdalton commented Oct 24, 2012

_.where which iterates over attrs with a for-in (inherited and own props) shouldn't use _.isEmpty (only own properties) to exit early.

@jashkenas
Owner

attrs in this case is supposed to be a naked object ... so in common use there shouldn't be any difference between using a hasOwnProperty check or not -- but it won't hurt too much to add one.

@jashkenas jashkenas added a commit that closed this issue Nov 12, 2012
@jashkenas Fixes #838 -- use hasOwnProperty when looping through _.where attrs, …
…for healthy paranoia's sake
c42a3e6
@jashkenas jashkenas closed this in c42a3e6 Nov 12, 2012
@jdalton
jdalton commented Nov 12, 2012

Is this ok? I was really meaning to drop isEmpty use because of existing iteration behavior (own & inherited props). Will changing this to iterating only-own props break Backbone compat?

@jdalton
jdalton commented Nov 12, 2012

I preserved the behavior of iterating own & inherited props in lodash by doing this:
https://github.com/bestiejs/lodash/blob/v0.9.2/lodash.js#L2521-2536

@jashkenas
Owner

It shouldn't break anything. attrs is just an empty object with no enumerable prototype properties to speak of.

@jdalton
jdalton commented Nov 12, 2012

Ok cool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment