prototype

// Human 생성자 함수
var Human = function (type) {
    this.type = type || 'human';
}

// Human static method
Human.isHuman = function (human) {
    return human instanceof Human;
}

// Human prototype method or instance method // 상속되는 메서드
Human.prototype.breathe = function () {
    return 'h-a-a-a-m';
}

// Hj 자식 클래스 생성자 함수
var Hj = function (type, firstName, lastName) {
    Human.apply(this, arguments);
    this.firstName = firstName;
    this.lastName = lastName;
}

// Hj.prototype에 Human.prototype 연결
Hj.prototype = Object.create(Human.prototype);
Hj.prototype.constructor = Hj; // 상속하는 부분
Hj.prototype.sayName = function () {
    return this.firstName + ' ' + this.lastName;
}

var oldHj = new Hj('human', 'hyungju', 'lee');
console.log(Human.isHuman(oldHj)); // true
console.log(oldHj.breathe()); // h-a-a-a-m // 상속 가능한 부모의 prototype method엔 접근할 수 있음
console.log(oldHj.sayName()); // hyungju lee
console.log(oldHj.isHuman); // undefined // 부모 클래스의 static method엔 접근 못함