We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hasOwnProperty
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"
({})['toString'] // function toString() { [native code] }
The solution is to use hasOwnProperty.
The text was updated successfully, but these errors were encountered:
@mathiasbynens thanx for pointing this out, will use the existing one as an antipattern and put up one with hasOwnProperty as the preferred way.
Sorry, something went wrong.
8a465a4
Preferred method 3 seems to have the same problem, isn't it?
Yes it looks like it does, plus arguments.callee is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee)
No branches or pull requests
If param is e.g.
"toString"
this will cause problems.({})['toString'] // function toString() { [native code] }
The solution is to use
hasOwnProperty
.The text was updated successfully, but these errors were encountered: