loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var Letter = function(value)  {
  this.value = value;
  this.iam = function() { 
   return `I am the ${this.constructor.name} ${this.value}`;
  };
  this.alphabet = function() { 
   return this.value + " is letter No." + '0abcdefghijklmnopqrstuvwxyz'.indexOf(this.value) + " in the alphabet";
  };
};

var test = new Letter("a");
console.log(test.iam());
console.log(test.alphabet());


var Vowel = function(value) { 
  if (["a","e","i","o","u"].indexOf(value) === -1)
        throw new SyntaxError("Invalid vowel");
  // Call parent constructor.
  Letter.call(this,value);
};

// Assign child prototype same prototype as parent 
Vowel.prototype = Object.create(Letter.prototype);
// Reassign correct constructor to child
Vowel.prototype.constructor = Vowel;


var test2 = new Vowel("i");
console.log(test2.iam());
console.log(test2.alphabet());
Native Browser JavaScript