Open YeonjuOHYE opened 5 years ago
let id1 = Symbol("id");
let id2 = Symbol("id");
alert(id1 == id2); // false
왜냐 고유값이므로 이를 키로 쓰면 이 값을 모르는 third party는 키를 절대 모르므로 값을 가져올 수 없다
let user = { name: "John" };
let id = Symbol("id");
user[id] = "ID Value";
alert( user[id] ); // we can access the data using the symbol as the key
</script>
let id = Symbol("id");
let user = {
name: "John",
[id]: 123 // not just "id: 123"
};
// read from the global registry
let id = Symbol.for("id"); // if the symbol did not exist, it is created
// read it again (maybe from another part of the code)
let idAgain = Symbol.for("id");
// the same symbol
alert( id === idAgain ); // true
// get symbol by name
let sym = Symbol.for("name");
let sym2 = Symbol.for("id");
// get name by symbol
alert( Symbol.keyFor(sym) ); // name
alert( Symbol.keyFor(sym2) ); // id
오브젝트 파인튜닝 하는데 사용될 수 있다..! https://docs.w3cub.com/javascript/global_objects/symbol/hasinstance/ https://jaeyeophan.github.io/2017/04/20/ES6-8-Symbol/
네이티브
내장 함수를 말한다
3.1 내부 [[Class]]
typeof 의 object에는 [[Class]]라는 내부프로퍼티가 추가로 붙는다. 직접 확인은 불가능하고, Object.prototype.toString()으로 확인 가능 이는 내장 네이티브 생성자를 가르킨다.(그렇지 않을 떄도 있다 -> null,undefined)
3.1 내부 [[Class]]
래퍼 박싱을 통해 primitive 함수 래핑하지만 이는 기본적으로 됨으로 수동으로 래핑하지 마라!!
3.2 래퍼 박싱
스크립트에서 알아서 해줌 -> 왠만하면 직접 하지마...
왜냐 bool은 객체로 인식되는데 bool은 truthy 따라서 수동 매핑하려면 Object사용해라
3.3 언박싱
valueOf를 사용해라
3.4 네이티브, 나는 생성자다