shichuan/javascript-patterns — Issue #6: Use `hasOwnProperty` in the memoization pattern
Author: mathiasbynens
Created: 2012-01-13 07:00:26+00:00
State: open

```js
var myFunc = function (param) {
if (!myFunc.cache[param]) {
var result = {};
// ... expsensive operation ...
myFunc.cache[param] = result;
}
return myFunc.cache[param];
};
```

If param is e.g. `"toString"` this will cause problems.

`({})['toString'] // function toString() { [native code] }`

The solution is to use `hasOwnProperty`.