본문 바로가기

Programming Practice

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.. 더보기
symbolic link Windows 의 '바로가기' 디렉토리와 유사하며, 실제 디렉토리처럼 동작1) 사용 예시여러 서버에 각각의 서비스가 구동되고 있는데, 서비스들 간에 파일을 공유할 필요가 생겨서 추후에 서버간 파일을 공유할 수 있는 공유 디렉토리를 만들었다고 하자.서비스의 파일 경로는 local 디렉토리 구조에 맞춰져 있어서 공유 디렉토리 경로로 변경하는 것이 어렵다. 이럴 경우 기존 local 디렉토리에서 공유 디렉토리로 symbolic link를 만든다. 2) 생성 방법ln -s cf. s : soft link (hard link 에 반대되는 개념)예를 들어서, home/contents/static/attach 디렉토리에서 home/share/contents/static/attach/temp 에 연결되는 temp 바로.. 더보기
delegation 1. delegation 이란?특정 element 에서 event가 발생하면, 해당 event 는 모든 상위 element로 전달되며(bubbling phase), 각 element 에 등록된 모든 event handler 가 호출된다.이때 상위 element에서는 하위 element 들을 대표 (delegation)해서 event handler 를 등록할 수 있다. 예를 들어, 아래 구조에서 더보기
Ajax 1. 기본jQuery 객체의 ajax method를 이용한다. ajax method 의 parameter 는 json 형식으로 설정되어 있다.ㄱ, 기본 사용$.ajax({url : ~, success : function() { }, error : function() {}, data : {}, timeout : ~ms}ㄴ. 간단히 사용모든 ajax 요청에는 url이 포함되어 있으므로, 아래와 같이 url 은 key 없이 데이터만 2. ajax method 의 parameter 인 json에 설정할 수 있는 key 종류key 설명 url 호출하는 url json 에 포함시키지 않고, url value 만 따로 빼서, json 밖에 둘 수 있다. ex) $.ajax ({confirmation.html, { s.. 더보기
javascript convention 1. 생성자 함수 내 private 변수는 변수명 앞에 _ 를 붙인다.2. 생성자 함수 명은 대문자로 시작하는 명사이다.3. jQuery 객체를 참조로 가지는 변수는 앞에 $를 붙인다. 더보기
Function 1. function 특징 1) 1종 객체 아래 사항 가능 - 변수에 할당 - function의 parameter 로 설정 - function 의 return type 으로 설정 - literal 로 설정 - 동적 property 설정 2. function이 유효한 범위 예를 들어, function a 안에서 function b 가 선언됐다고 하자. function a() { function b() { } } function b가 참조될 수 있는 범위는 function a 전체 => function 이 선언되기 전 참조 가능 (hoisting mechanism) cf. 변수가 참조될 수 있는 범위 - 변수 선언 ~ 변수가 선언된 함수 끝 ** javascript의 유효범위는 block 단위가 아니라 fu.. 더보기
jQuery? 1. jQuery의 목적1) HTML 요소 찾기2) HTML contents, attribute, style 변경3) animation4) event handling5) ajax 처리 2. jQuery 함수 항목 HTML element 찾기 element 속성 변경 element 생성 방법 $() $().doSomething(); $(); 예시 $("h1") $("h1").text("hello"); $("Hello!"); 3. element 선택 선택 function X function O children ("parent > children") ("parent").children("항목")** 모든 자식 요소 ("parent").children() descendant ("parent descendant".. 더보기
테스트 환경 구성 빠른 테스트를 위해 기존 방식에서 신규 방식으로 테스트 환경 구성을 변경한다. IDE Web Server library 구성 기존 eclipse Apache Tomcat Server 직접 구성 신규 Sublime Text http server (Node.js 의 npm를 통해 설치) bower (Node.js 의 npm를 통해 설치) 1. Sublime Text2 설치 http://www.sublimetext.com/2 에서 Download 해서 설치한다. Sublime Text3 는 현재 beta 버전이다. * http://www.hans.or.kr/2013/11/sublime-text3.html 를 참고해서 package-control을 설치한다. * Preferences - Package Contr.. 더보기