Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

skava / exotic   js

Repository URL to install this package:

Version: 2.0.8 

/ src / types / NATIVE / prototype / isPrototypeOf.ts

import { isNil } from '../../../types/primitive/nil'

const isPrototypeOf = Object.prototype.isPrototypeOf

/**
 * check if arg 1 is prototype of arg 2
 *
 * @TODO curry2
 * @memberOf is
 * @name isPrototypeOf
 * @since 3.0.0
 *
 * @param haystack check needle against
 * @param needle is prototype of haystack
 * @return needle isPrototypeOf haystack
 *
 * {@link https://tc39.github.io/ecma262/#sec-object.prototype.isprototypeof emca-is-prototype-of}
 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf mozilla-obj-isprototypeof}
 * @see {@link mozilla-obj-isprototypeof}
 * @see {@link emca-is-prototype-of}
 *
 * @example
 *
 *    class Eh extends Function {}
 *    class Canada extends Eh {}
 *    isPrototypeOf(Eh, Function) //=> true
 *    isPrototypeOf(Canada, Function) //=> true
 *    isPrototypeOf(Eh, Date) //=> false
 *
 *    isPrototypeOf({}, Object) //=> true
 *    isPrototypeOf({}, Array) //=> false
 *
 */
export default <Haystack = any, Needle extends keyof Haystack = any>(
  haystack: Haystack,
  needle: Needle
) => !isNil(haystack) && isPrototypeOf.call(haystack, needle)