JavaScript 객체 지향 프로그래밍

prototype

수업소개

JavaScript의 prototype이 필요한 이유와 prototype을 통해서 코드의 재사용성과 성능을 향상시키는 방법을 알려드립니다. 

 

 

 

강의1

prototype이 필요한 이유를 소개합니다. 

 

 

 

강의2

prototype을 이용해서 코드의 재사용성을 높이고, 성능을 향상시키는 방법을 소개합니다. 

 

 

 

코드

prototype.js (변경사항)

function Person(name, first, second, third){
    this.name=name;
    this.first=first;
    this.second=second;   
}

Person.prototype.sum = function(){
    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());

 

 

 

참고

[JavaScript] 프로토타입 이해하기 (오승환님)

 

댓글

댓글 본문
버전 관리
egoing
현재 버전
선택 버전
graphittie 자세히 보기