Using “Object.create” instead of “new”

Javascript 1.9.3 / ECMAScript 5 introduces Object.create, which Douglas Crockford amongst others has been advocating for a long time. How do I replace new in the code below with Object.create? var UserA = function(nameParam) { this.id = MY_GLOBAL.nextId(); this.name = nameParam; } UserA.prototype.sayHello = function() { console.log(‘Hello ‘+ this.name); } var bob = new UserA(‘bob’); … Read more

Understanding the difference between Object.create() and new SomeFunction()

I recently stumbled upon the Object.create() method in JavaScript, and am trying to deduce how it is different from creating a new instance of an object with new SomeFunction(), and when you would want to use one over the other. Consider the following example: var test = { val: 1, func: function() { return this.val; … Read more