weakMap
-
Javascript ES6 Map,WeakMap key/value 구조Javascript (ES6) 2020. 7. 30. 22:18
// Map & WeakMap //map은 key/value 구조 let wm = new WeakMap(); let myfun = function(){}; // 이 함수가 얼마나 실행됐는지 알려고 할때. wm.set(myfun,0); //key, value console.log(wm); //WeakMap {ƒ => 0} let count = 0; for (let i=0; i 10} myfun = null; console.log(wm.get(myfun)); //undefined (가비지 컬렉션으로 이동) //WeakMap 활용 (클래스 인스턴스 변수 보호(private)) const wm1 = new WeakMap(); function Area(height, width){ wm1.set(this, {hei..