Created
November 27, 2017 13:40
-
-
Save seogi1004/847d0898c0472735235d96c49f739bef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Person(firstName, lastName) { | |
// 객체 생성시 증가 | |
this.constructor.population++; | |
// ********************************************************************** | |
// PRIVATE VARIABLES AND FUNCTIONS | |
// 'PRIVELEGED METHODS'만 읽기/쓰기/수정 가능 | |
// ********************************************************************** | |
var alive = true; | |
function getFullName() { | |
return lastName + ", " + firstName; | |
} | |
// ********************************************************************** | |
// PRIVILEGED METHODS | |
// 공개적으로 호출할 수 있으며, 'PRIVATE' 항목에 유일하게 접근 가능 | |
// 하지만 수정할 수 없고, 'PUBLIC'과 대체 가능 | |
// ********************************************************************** | |
this.toString = function(){ | |
return getFullName(); | |
}; | |
this.isAlive = function() { | |
return alive; | |
}; | |
// ********************************************************************** | |
// PUBLIC PROPERTIES -- 누구나 읽기/쓰기 가능 | |
// ********************************************************************** | |
this.age = 1; | |
}; | |
// ************************************************************************* | |
// PUBLIC METHODS -- 누구나 읽기/쓰기 가능 | |
// ************************************************************************* | |
Person.prototype.addAge = function() { | |
this.age++; | |
}; | |
// ************************************************************************* | |
// PROTOTYOPE PROERTIES -- 누구나 읽기/쓰기 가능 (but may be overridden) | |
// ************************************************************************* | |
// Person.prototype.age = 0; | |
// ************************************************************************* | |
// STATIC PROPERTIES -- 누구나 읽기/쓰기 가능 | |
// ************************************************************************* | |
Person.population = 0; | |
// ************************************************************************* | |
// STATIC METHODS -- 누구나 읽기/쓰기 가능 | |
// ************************************************************************* | |
Person.showTotalPopulation = function (msg) { | |
alert(msg + " : " + Person.population); | |
} | |
var personList = [ new Person('Jae-Seok', 'Hong'), new Person('Ji-Sung', 'Jung') ]; | |
$("#result") | |
.append("'" + personList[0] + "'과 '" + personList[1] + "'이 태어났습니다.") | |
.append("현재 인구는 " + Person.population + "명 입니다."); | |
for(var i = 0; i < 25; i++) { | |
personList[0].addAge(); | |
personList[1].addAge(); | |
} | |
$(“#result") .append("'" + personList[0] + "'은 " + personList[0].age + "살이 되었습니다."); | |
Person.showTotalPopulation("총 인구"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment