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 / hasPrototype.ts

import { ObjWithProto } from '../../../../typings'
import { isNil } from '../../primitive/nil'
import { hasOwnProp } from '../../attributes/properties/hasOwnProperty'
import { isObj } from '../../obj'

/**
 * @desc check if it has prototype property
 * @param {*} x value to check
 *
 * @return {Boolean}
 *
 * {Number | undefined}  1 | 2 could put enum options for checking
 *
 * @example
 *   hasPrototype(class {})
 *   //=> true
 *
 *   hasPrototype(new class {})
 *   //=> true
 *
 *   hasPrototype(function() {})
 *   //=> true
 *
 *   hasPrototype(() => {})
 *   //=> false || true // babel MAY add one, but it isn't there in ecmascript
 *
 *   hasPrototype(Object.create(null))
 *   //=> false
 *
 *   hasPrototype({})
 *   //=> true
 *
 *   hasPrototype(undefined)
 *   //=> false
 *
 *   hasPrototype(true)
 *   //=> true // try in browser `true.__proto__`
 */
function hasPrototype(x: any): x is ObjWithProto {
  if (isNil(x)) {
    return false
  } else if (isObj(x.prototype)) {
    return true
  } else if (isObj(x.__proto__)) {
    return true
  } else {
    return false
  }
  // if (Object.prototype.hasOwnProperty.call(x, 'prototype')) {
  //   return true
  // }
  // else if (Object.prototype.hasOwnProperty.call(x, '__proto__')) {
  //   return true
  // }
}

export { hasPrototype }
export default hasPrototype