Created
October 5, 2016 11:47
-
-
Save dobestan/67f378c9fec06aaa4d4ac5947d4e63e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Scope - Function level scope | |
// Object - call by reference | |
// Function-level Scope | |
// Object ( primitive data types - string, number, boolean, null, undefined ) - call by reference | |
// 이런 문제가 생기는 원인? scope block level scope 가 아니라, function level scope 를 가지기 때문이다. | |
// 이런 문제를 해결할 수 있는 방법? function 으로 묶는다. | |
arr = []; | |
for (var i=0; i<5; i++) { | |
// var element = function(n) { return i * n }; | |
var element = (function(veryI) { return function(n) { return veryI * n } })(i); | |
arr.push(element); | |
} | |
// console.log(arr[0](100)); // 0 | |
// console.log(arr[1](100)); // 100 | |
// console.log(arr[2](100)); // 200 | |
// console.log(arr[3](100)); // 300 | |
// console.log(arr[4](100)); // 400 | |
// Primitive Data Types - Number, String, Boolean, Null, Undefined // Object | |
// Object => State, Behavior | |
// Primitive Data Type 은 객체가 아니다 (O) | |
// 자바스크립트의 모든 자료형은 객체다 (O) | |
var name = "An Su Chan"; | |
console.log(typeof name); // string 은 객체가 아니다. | |
console.log(name.toUpperCase()); // string 은 객체다. | |
var nameObj = new String("An Su Chan"); | |
console.log(typeof nameObj); | |
console.log(nameObj); | |
// var student = { | |
// name: "Suchan An", | |
// introduce: function() { console.log(this.name) } | |
// }; | |
// | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment