In principle, you do not need anything. Javascript just has slightly different ways of creating objects which (of course) work slightly different. In your examples:
function a() = {}; // syntax error, correct syntax is function a() {}
var b = new a(); // creates a new instance of a - assuming a is a constructor function
var c = {}; // creates a new object literal
c.__proto__ = a.prototype // assings the prototype of function a to __proto__ of c
As a basic rule of thumb, if you simply want to create an object use the object literal way. If you want to use the constructor pattern you wanna use the new
keyword to create instances using the constructor - you can also create instances manually but new
is syntactic sugar. I would try to avoid directly assigning objects to the __proto__
since that is usually done internally. Another way to create objects based on other objects is using Object.create({})
.
The latest ES syntax introduces the class
keyword to abstract out the constructor pattern. This is a polarizing feature of the language. Read more here.
Hope it helps, happy learning!