prototype

상속을 구현하기위한 문법으로 prototype이 있다. prototype에 값을 추가하면 모든 자식들이 물려받을 수 있다.

function Constructor(name, age){
  this.name = name;
  this.age = age;
  this.sayHi = function(){
    console.log('hello, myname is ' + this.name);
  }
}

Constructor.prototype.gender = '';

var student1 = new Constructor('kim', 15);
var student2 = new Constructor('lee', 17);

prototype에 값을 추가하면 모든 자식들이 물려받을 수 있다. 이제 student1.gender로 활용이 가능하다.