Mostly availability.
Object.create()
is available in ES5-compatible browsers, while_.defaults()
will function in older, ES3-based browsers (IE8, IE7, etc.).Also for objects you didn't
create()
.If the object already exists, you can't count on being able to alter its
[[Prototype]]
after-the-fact to establish the desires inheritance.It's possible in some browsers, but not standard.
It might make things easier with more than 1
defaults
object._.defaults(options, config, defaults);
This is possible with prototype chains, but you have to establish one.
var defaults = { /* ... */ }; var config = Object.create(defaults); config.mixed = true;
var iceCream = Object.create(config); iceCream.flavor = 'chocolate';
But, in general, they serve very similar purposes. They just do so from different perspectives:
_.default()
iterates to find and set what's missing.Object.create()
uses prototype chains to inherit what's missing.
So, which to use is largely up to you and your personal preferences.