Closure란? 외부함수의 변수에 접근할 수 있는 내부 함수를 가리킨다.클로저를 사용하게 되면 전역변수의 오남용을 줄일 수 있는 효과가 있다. function Person() { var _name = 'Jason'; this.showName = function () { console.log(_name); }; } var student = new Person(); student.showName(); console.log(student._name); // 결과값 : Jason, undefined 로컬변수 _name은 private 변수, 즉 외부에서 접근할 수 없는 형태로 오직 showName함수를 통해서만 _name 값을 받아올 수 있다. ※ 클로저는 처리 속도와 메모리 측면에서 성능에 좋은 영향을 끼치..
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..