반응형 inheritance1 Javascript 상속(inheritance)과 프로토타입(prototype) 상속 객체는 연관된 로직들로 이루어진 작은 프로그램이라고 할 수 있다. 상속은 객체의 로직을 그대로 물려 받는 또 다른 객체를 만들 수 있는 기능을 의미한다. 단순히 물려받는 것이라면 의미가 없을 것이다. 기존의 로직을 수정하고 변경해서 파생된 새로운 객체를 만들 수 있게 해준다. 상속의 기본적인 예. function Person(name){ this.name = name; } Person.prototype.name=null; Person.prototype.introduce = function(){ return 'My name is '+this.name; } var p1 = new Person('jin seok'); document.write(p1.introduce()+" "); .prototype이라는.. 2020. 11. 13. 이전 1 다음 반응형