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

Very simply said, new X is Object.create(X.prototype) with additionally running the constructor function. (And giving the constructor the chance to return the actual object that should be the result of the expression instead of this.) That’s it. 🙂 The rest of the answers are just confusing, because apparently nobody else reads the definition of new … Read more

What is the reason to use the ‘new’ keyword at Derived.prototype = new Base

WeatherWidget.prototype = new Widget; The new keyword calls Widget as a constructor and the return value is assigned to the prototype property. (If you would omit new, you would not call Widget unless you added an argument list, (). However, calling Widget that way might not be possible. It would certainly have the potential to … Read more

What are the nuances of scope prototypal / prototypical inheritance in AngularJS?

Quick answer: A child scope normally prototypically inherits from its parent scope, but not always. One exception to this rule is a directive with scope: { … } — this creates an “isolate” scope that does not prototypically inherit. This construct is often used when creating a “reusable component” directive. As for the nuances, scope … Read more

Prototypical inheritance – writing up [duplicate]

Constructor function introduction You can use a function as a constructor to create objects, if the constructor function is named Person then the object(s) created with that constructor are instances of Person. var Person = function(name){ this.name = name; }; Person.prototype.walk=function(){ this.step().step().step(); }; var bob = new Person(“Bob”); Person is the constructor function. When you … Read more