Javascript prototype inheritance 자바스크립트에서 상속(inheritance)은 prototype을 이용하여 코드를 재사용할 수 있다. new 연산자를 이용한 classical한 방식과 Object.create()를 이용한 prototypal한 방식이 있다. // baseClass function Person() { this.sayJob = false; } // prototype method Person.prototype.say = function () { console.log(this.sayJob ? "Yes" : "No"); }; // subClass function Programmer() { Person.call(this); } Programmer.prototype = Ob..
Object creation patterns ▶ 자바스크립트 Javascript는 Java 와 같이 Class 가 존재하지 않는다.기존의 객체를 복사하여 새로운 객체를 생성하는 프로토타입 기반의 언어이다. 자바스크립트의 가장 큰 특징은 유연함(flexibility)이다.객체를 생성하는데 있어서 여러가지 패턴들을 살펴보겠다. ▶ Factory pattern function InfoFactory(name, age, job) { var person = {}; person.name = name; person.age = age; person.job = job; person.print = function () { console.log('Name: ' + this.name + ', Age: ' + this.age +..