수업소개
이 수업은 불필요하게 어렵습니다. 동일한 역할을 하면서도 훨씬 이해하기 쉬운 class 상속 수업을 보실 것을 권해봅니다. 물론 보셔도 됩니다. ㅎㅎ
강의1
강의2
코드
constructor-inheritance.js (변경사항)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | function Person(name, first, second){ this .name = name; this .first = first; this .second = second; } Person.prototype.sum = function (){ return this .first + this .second; } function PersonPlus(name, first, second, third){ Person.call( this , name,first,second); this .third = third; } PersonPlus.prototype.avg = function (){ return ( this .first+ this .second+ this .thrid)/3; } var kim = new PersonPlus( 'kim' , 10, 20, 30); console.log( "kim.sum()" , kim.sum()); console.log( "kim.avg()" , kim.avg()); |
강의3
코드
constructor-inheritance.js (변경사항)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | function Person(name, first, second){ this .name = name; this .first = first; this .second = second; } Person.prototype.sum = function (){ return this .first + this .second; } function PersonPlus(name, first, second, third){ Person.call( this , name,first,second); this .third = third; } // PersonPlus.prototype.__proto__ = Person.prototype; PersonPlus.prototype = Object.create(Person.prototype) PersonPlus.prototype.avg = function (){ return ( this .first+ this .second+ this .third)/3; } var kim = new PersonPlus( 'kim' , 10, 20, 30); console.log( "kim.sum()" , kim.sum()); console.log( "kim.avg()" , kim.avg()); |
강의4
constructor 속성의 의미와 용도를 살펴봅니다.
강의5
코드
constructor-inheritance.js (변경사항)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | function Person(name, first, second){ this .name = name; this .first = first; this .second = second; } Person.prototype.sum = function (){ return this .first + this .second; } function PersonPlus(name, first, second, third){ Person.call( this , name,first,second); this .third = third; } // PersonPlus.prototype.__proto__ = Person.prototype; PersonPlus.prototype = Object.create(Person.prototype); PersonPlus.prototype.constructor = PersonPlus; PersonPlus.prototype.avg = function (){ return ( this .first+ this .second+ this .third)/3; } var kim = new PersonPlus( 'kim' , 10, 20, 30); console.log( "kim.sum()" , kim.sum()); console.log( "kim.avg()" , kim.avg()); console.log( 'kim.constructor' , kim.constructor); |