수업소개
class를 통해서 객체를 생성할 때 모든 객체가 공유하는 공통(prototype)의 객체를 생성하는 방법을 소개합니다.
강의
코드
class.js (변경사항)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | class Person{ constructor(name, first, second){ this .name = name; this .first = first; this .second = second; } sum(){ return 'prototype : ' +( this .first+ this .second); } } var kim = new Person( 'kim' , 10, 20); kim.sum = function (){ return 'this : ' +( this .first+ this .second); } var lee = new Person( 'lee' , 10, 10); console.log( "kim.sum()" , kim.sum()); console.log( "lee.sum()" , lee.sum()); |