forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid prototype builtin
hasOwnProperty
(denoland/std#577)
Original: denoland/std@d36bff3
- Loading branch information
Showing
4 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. | ||
|
||
/** | ||
* Determines whether an object has a property with the specified name. | ||
* Avoid calling prototype builtin `hasOwnProperty` for two reasons: | ||
* | ||
* 1. `hasOwnProperty` is defined on the object as something else: | ||
* | ||
* const options = { | ||
* ending: 'utf8', | ||
* hasOwnProperty: 'foo' | ||
* }; | ||
* options.hasOwnProperty('ending') // throws a TypeError | ||
* | ||
* 2. The object doesn't inherit from `Object.prototype`: | ||
* | ||
* const options = Object.create(null); | ||
* options.ending = 'utf8'; | ||
* options.hasOwnProperty('ending'); // throws a TypeError | ||
* | ||
* @param obj A Object. | ||
* @param v A property name. | ||
* @see https://eslint.org/docs/rules/no-prototype-builtins | ||
*/ | ||
export function hasOwnProperty<T>(obj: T, v: PropertyKey): boolean { | ||
if (obj == null) { | ||
return false; | ||
} | ||
return Object.prototype.hasOwnProperty.call(obj, v); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters