I\'ve been using the new keyword in JavaScript so far. I have been reading about Object.create and I wonder if I should use it instead. What I don\
As already mentioned, Object.create() is commonly used when you want an easy way to set the prototype of a new object. What the other answers fail to mention though, is that constructor functions (which require new) are not all that different from any other function.
In fact, any function can return an object, and it's common in JavaScript to see factory functions (like constructors, but they don't require new, or use this to refer to the new object). Factory functions often use Object.create() to set the prototype of the new object.
var barPrototype = {
open: function open() { /* ... */ },
close: function close() { /* ... */ },
};
function createBar() {
return Object.create(barPrototype);
}
var bar = createBar();