본문 바로가기
[JavaScript/Tutorial] Closure 와 Function.bind 의 사용. Closure와 Function.bind 의 사용 [이전강좌] Scope. var 없이 변수 정의하면? Global variable 접근방법은? Closure Closure 는 Scope 의 확장판으로 이해할 수 있다. Function 에 Parameter 형태로 Variable 을 전달하여, 해당 변수를 Local 화 시키는 것도 Closure이고, Outer scope 접속을 위해 임의의 variable 에 this 를 저장한 후, sub procedure 를 실행하는 형태도 Closure 하고 한다. // 변수 로컬화 closure var localizeFunction = function( localizedIndex ){ return function(){ alert( localizedIndex );.. 2013. 5. 26.
[JavaScript/Tutorial] Scope. var 없이 변수 정의하면? Global variable 접근방법은? Scope. var 없이 변수 정의하면? Global variable 접근방법 [이전강좌] this 란 무엇인가? this 가 가르키는 건 무엇인가? 주의사항은? Global Variable 접근방법 global scope 는 window object 를 통해서 접근가능. window.variable var 없이 변수정의 하면? 변수선언시 var 를 잊어버리고 쓰지 않으면, 자동으로 global 로 정의된다.이는 코드의 가독성을 떨어뜨리는 나쁜 코드의 지름길이므로 피해야 한다. [다음강좌] Closure 와 Function.bind 의 사용. global scope, Global Variable, javascript, javascript tutorial, js, js tutorial, Scope, Var.. 2013. 5. 24.
[JavaScript/Tutorial] this 란 무엇인가? this 가 가르키는 건 무엇인가? 주의사항은? this 란 무엇인가? this 가 가르키는 건 무엇인가? 주의사항은? [이전강좌] typeof 사용시의 주의사항, array type 판별코드. this 란 무엇인가? this 키워드는, 해당 function 을 invoke 한 object 를 가르키는 데 사용된다. this 가 가르키는 것은 어떻게 판별하는가? 1. Function.call 이나 Function.apply 를 통해 function call 을 하게 되면, call() 이나 apply() 의 첫번쨰 argument 가 this 가 된다. 만약 Function.call 이나 Function,apply 의 첫번째 argument 로 null 이나 undefined 가 들어왔다면 this는 global object 를 참조한다. 2. 만약 .. 2013. 5. 24.
[JavaScript/Tutorial] typeof 사용시의 주의사항, array type 판별코드. typeof 사용시 주의사항, array type 판별코드 [이전강좌] Function 정의 방법 typeof 사용시 주의사항 typeof operator 를 사용하면, 그 값이 string type 으로 return 된다.이 중에서 조심해야 할 data type 은 array 와 null type 이다. typeof function // "function"typeof object // "object"typeof array // "object" - 주의!!typeof string // "string"typeof number // "number"typeof null // "object" - 주의!! array 판별 코드 typeof operator 만 이용해서는, 검사하는 변수가 object 인지, arr.. 2013. 5. 23.
[JavaScript/Tutorial] Function 정의 방법 Function 정의 방법 [이전강좌] Object 특징, method와 properties 의 구분, literal Function 은 다음의 두가지 형태로 정의될 수 있다. function foo(){ } var foo = function() { } [다음강좌] typeof 사용시의 주의사항, array type 판별코드. function declaration, function 정의, javascript, javascript tutorial, js, js tutorial, tutorial, 강좌, 기초 강좌, 방법, 튜토리얼, 함수 정의 2013. 5. 22.
[JavaScript/Tutorial] Object 특징, method와 properties 의 구분, literal Object의 특징, method 와 properties의 구분, literal [이전강좌] Array literal, undefined 값들, 관련 함수들. Object 의 특징 Object 는 한개 이상의 key-value pair 로 구성된다.key 는 string type이 보통 사용되고, value 는 어떤 type 이든 가능하다. Method 와 Properties 의 차이 Object 의 하나의 key-value 라도 value 에 function 이 assign 되어 있다면 그 object는 method 라 불린다.value 에 function 을 담고 있지 않은 object는 properties 라 부른다. Object literal Object 를 literal 형식으로 정의할 때는 v.. 2013. 5. 21.
[JavaScript/Tutorial] Array literal, undefined 값들, 관련 함수들. Array literal, undefined 값들, array 관련 함수들 [이전강좌] 조건문(Conditional Statement) 에서의 주의사항 및 switch 문. Array literal 과 undefined 값들 Array 를 정의할 때는 literal 이 추천된다.( Array를 Constructor로 사용해서 정의하면, constructor 의 parameter 관련하여 실수가 잘 발생한다. ) myArray[ 3 ] = "1"; 이 경우 만약 0, 1, 2 가 값이 없었다면0, 1, 2 index 자리에는 자동으로 undefined 가 채워진다. for ( var i in myArray ){console.log( i );} 위와 같은 코드를 통해 array의 모든 값을 iterate 할.. 2013. 5. 17.
반응형