Parasitic Inheritance in Javascript using pure Prototypal approach

I am learning OOP in JavaScript and have gone through various posts on the same. It has come to my knowledge that Douglas Crockford prescribes a pure prototypal approach to inheritance as opposed to the classical approach.

The following code taken from here implements Crockford’s method:

var superInstance = {
  member1: 'superMember1',
  member2: 'superMember2'

var subInstance = Object.create(superInstance);
subInstance.member3 = 'subMember3';

I understand that Crockford’s approach does away with constructor functions (correct me if I am wrong). Does this mean that the only way to initialize object members with this approach is by using object literals as shown in above code? Also, how do I implement parasitic inheritance with this approach to allow shared members, private variables and non-scalar values in the parent class (refer this post)?

Crackford mentions “maker functions” in his article, but does not give any example code for it. It would be great if someone could demonstrate parasitic inheritance using Crackford’s pure prototypal approach.


Source: oop

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.