<commit_before># hasPrototype

> Test if an object's prototype chain contains a provided prototype.


<section class="intro">

</section>

<!-- /.intro -->


<section class="usage">

## Usage

``` javascript
var hasPrototype = require( '@stdlib/utils/has-prototype' );
```

#### hasPrototype( obj, prototype )


Tests if an `object`'s prototype chain contains a provided `prototype`.

``` javascript
var inherit = require( '@stdlib/utils/inherit' );

function Foo() {
    return this;
}

function Bar() {
    return this;
}
inherit( Bar, Foo );

var bar = new Bar();

var bool = hasPrototype( bar, Foo.prototype );
// returns true
```

</section>

<!-- /.usage -->


<section class="notes">

## Notes

* The function returns `false` if provided a primitive value.

  ``` javascript
  var bool = hasPrototype( 5, Number.prototype );
  // returns false

  bool = hasPrototype( 'beep', String.prototype );
  // returns false

  bool = hasPrototype( true, Boolean.prototype );
  // returns false
  ```

* The function throws a `TypeError` if provided a `prototype` value which is neither an `object` (except `null`) or a `function`.

  ``` javascript
  var bool = hasPrototype( Object.create( null ), null );
  // throws <TypeError>
  ```

* `hasPrototype()` is generally more robust than the `instanceof` operator. Consider an architecture which does not use constructors.

  ``` javascript
  // Functionally similar to `Object.create()`...
  function createObject( proto ) {
      function Ctor(){}
      Ctor.prototype = proto;
      return new Ctor();
  }
  var superProto = {
      'beep': 'beep'
  };
<commit_msg>Reword sentence<commit_after># hasPrototype

> Test if an object's prototype chain contains a provided prototype.


<section class="intro">

</section>

<!-- /.intro -->


<section class="usage">

## Usage

``` javascript
var hasPrototype = require( '@stdlib/utils/has-prototype' );
```

#### hasPrototype( obj, prototype )


Tests if an `object`'s prototype chain contains a provided `prototype`.

``` javascript
var inherit = require( '@stdlib/utils/inherit' );

function Foo() {
    return this;
}

function Bar() {
    return this;
}
inherit( Bar, Foo );

var bar = new Bar();

var bool = hasPrototype( bar, Foo.prototype );
// returns true
```

</section>

<!-- /.usage -->


<section class="notes">

## Notes

* The function returns `false` if provided a primitive value.

  ``` javascript
  var bool = hasPrototype( 5, Number.prototype );
  // returns false

  bool = hasPrototype( 'beep', String.prototype );
  // returns false

  bool = hasPrototype( true, Boolean.prototype );
  // returns false
  ```

* The function throws a `TypeError` if provided a `prototype` value which is neither an `object` (except `null`) or a `function`.

  ``` javascript
  var bool = hasPrototype( Object.create( null ), null );
  // throws <TypeError>
  ```

* `hasPrototype()` is generally more robust than the `instanceof` operator. Consider the following example which does not use constructors:

  ``` javascript
  // Functionally similar to `Object.create()`...
  function createObject( proto ) {
      function Ctor(){}
      Ctor.prototype = proto;
      return new Ctor();
  }
  var superProto = {
      'beep': 'beep'
  };

{'fraction_non_alphanumeric': 0.1439159975293391, 'fraction_numerical': 0.0006176652254478073, 'mean_word_length': 3.4491758241758244, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6435684', 'n_tokens_mistral': 993, 'n_tokens_neox': 939, 'n_words': 328}