상속
상속
function Person(name){
this.name = name;
this.introduce = function(){
return 'My name is '+this.name;
}
}
var p1 = new Person('egoing');
document.write(p1.introduce()+"<br />"); //My name is egoingfunction Person(name){ // 생성자에 의해 객체가 생성이
this.name = name;
}
Person.prototype.name=null; // name 이라는 프로포
Person.prototype.introduce = function(){ // introduce 라는 메소드
return 'My name is '+this.name;
}
function Programmer(name){
this.name = name;
}
Programmer.prototype = new Person(); // 객체화 시킴
var p1 = new Programmer('egoing'); // new Programmer -> p1
document.write(p1.introduce()+"<br />"); //My name is egoing
// p1 introduce 메소드가 실행Last updated