JavaScript
Result
Run
License
function Human(name, gender, age, position) { this.name = name; this.gender = gender; this.age = age; this.position = position; this.getName = function() { return this.name; } } function Child(name, gender, age, position, child) { Human.apply(this, arguments); this.childName = child; this.getChildName = function() { return this.name + "의 자식 " + this.childName; } } Child.prototype = Object.create(Human.prototype); Child.prototype.constructor = Child; var myFather = new Child("김철수", "남", 45, "아버지", "김민희"); var myMother = new Child("이민희", "여", 40, "어머니", "김준호"); console.log(myFather.getName()); console.log(myFather.getChildName()); console.log(myMother.getName()); console.log(myMother.getChildName());
Console
expand_less
License
License
by DevDic
Close