标签:bsp fun strong code add key pre span else
function addTo80(n ) { return 80 + n; } function memoizedAddTo80 (fn) { let cache = {}; return (n) => { /*keyword ‘in‘ to check prop exists*/ if (n in cache) { console.log(‘from cache‘) return cache[n] } else { console.log(‘from calculation‘) cache[n] = fn(n) return cache[n] } } } const memoAdd = memoizedAddTo80(addTo80); memoAdd(5) // ‘from calculation‘ 85 memoAdd(5) // ‘from cache‘ 85 memoAdd(6) // ‘from calculation‘ 86
[Javascript] Keyword 'in' to check prop exists on Object
标签:bsp fun strong code add key pre span else
原文地址:https://www.cnblogs.com/Answer1215/p/11966743.html