Skip to content

Commit

Permalink
Bind hasOwnProperty once
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Feb 12, 2021
1 parent 562c64e commit b90e7c6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export type DeepPartial<T> = {
: T[K];
};

/**
* Make `Object.prototype.hasOwnProperty` a reusable utility function.
*/
const hasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);

/**
* Check if `value` is a simple object.
*/
Expand Down Expand Up @@ -46,7 +51,7 @@ export function assign<T>(target: T, value: DeepPartial<T>) {
} else if (isObject(value)) {
if (isObject(target)) {
for (const key of Object.keys(value)) {
if (Object.prototype.hasOwnProperty.call(target, key)) {
if (hasOwnProperty(target, key)) {
(target as any)[key] = assign(
(target as any)[key],
(value as any)[key]
Expand Down

0 comments on commit b90e7c6

Please sign in to comment.