본문 바로가기

closure 예제 및 자세한 설명은 아래 mozilla 페이지 참고.https://developer.mozilla.org/en/docs/Web/JavaScript/Closures 1. 개념1) closure?a function and the environment in which that function was created 2) when a function created?javascript 의 thread 가 function을 선언한 부분을 execute할때.** inner function 은 parent function 이 executed 될 때, created된다. parent function 이execute될 때마다 inner function은 created된다. 3) environment?local varia.. 더보기
prototype 1. 기본 구조 (출처 : The Secret of Javascript Ninja) 2. 참조 조정 생성자 함수의 property를 먼저 참조 -> prototype 의 property 참조 3. 생성자와 객체타입 객체의 constructor property 활용 1) 객체가 어떤 생성자함수로 만들어졌는지 확인 2) 특정 객체 생성한 생성자함수를 활용해 다른 객체 생성 function Journey() {}; var journey = new Journey(); console.log(journey.constructor); //function Journey() {}; console.log(journey instanceof Journey); //true console.log(typeof journey); //.. 더보기
함수 호출 4가지 방식이 있음. 1) 함수로 호출2) 메서드로 호출 3) 생성자로 호출 4) apply, call 로 호출함수에 암묵적으로 전달되는 매개변수 중 this 가 있음. this는 함수를 호출한 객체를 가리키며, 함수 context라고 함.함수 호출 방식에 따라 this 가 다름 1) 함수로 호출 호출 예 this function trip() {}; trip(); var tour = function(){};tour(); window (전역 context) 2) 메서드로 호출 호출 예 this var city = { trip : function () { return this;} } city.trip(); var city = {}; city.trip = function() {return this;} city.. 더보기