doowb / sort-object

Sort the keys in an object.
MIT License
37 stars 6 forks source link

add {} to extend #4

Closed jonschlinkert closed 11 years ago

jonschlinkert commented 11 years ago

Rather than overwriting the "default" options object (https://github.com/helpers/sort-object/blob/master/sort-object.js#L18) it's better to add an empty object as the first paramter, and then extend that.

Essentially, what's happening is something like this:

_.extend(dest, src1, ..., srcn) 
doowb commented 11 years ago

Yeah, I was thinking of that when I wrote it originally. But I didn't use that method because I'm already creating a new object literal when calling _extend. Since I'm doing it that way, there isn't a reference to an original object that would get changed.

I don't know if there's a performance impact on creating 2 object literals or creating a defaults object, then passing those in. I might just go for readability and do this...

var defaults = {
  order: 'asc'
};

var opts = _extend({}, defaults, options);
jonschlinkert commented 11 years ago

Yeah I see what you mean, I just use it as a best practice

doowb commented 11 years ago

Closing per tests done in #9