Your syntax is a bit off in the first example, but yes, these will result in objects that are similar. In the first example, it should be:
var Person = {
hopes: function(){},
dreams: function(){}
};
There are some subtle differences though. Using the new
keyword causes an object to be added to the prototype chain, e.g. Alice
will now use Human
's prototype chain. Object.create
sets the object's prototype to the parameter, e.g. Person
is John
's prototype. These generally will be similar, except if you do Object.create(null)
, in which case you don't get the basic object prototype as if you did new Object();
You can run performance tests here http://jsperf.com/obj-create-vs-new/4