time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (2857B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # isMethodIn
     22 
     23 > Test if an object has a specified method name, either own or inherited.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var isMethodIn = require( '@stdlib/assert/is-method-in' );
     31 ```
     32 
     33 #### isMethodIn( value, property )
     34 
     35 Returns a `boolean` indicating if a `value` has a specified method name, either own or inherited.
     36 
     37 ```javascript
     38 var value = {
     39     'beep': 'boop'
     40 };
     41 
     42 var bool = isMethodIn( value, 'toString' );
     43 // returns true
     44 
     45 bool = isMethodIn( value, 'beep' );
     46 // returns false
     47 
     48 bool = isMethodIn( value, 'bap' );
     49 // returns false
     50 ```
     51 
     52 </section>
     53 
     54 <!-- /.usage -->
     55 
     56 <section class="notes">
     57 
     58 ## Notes
     59 
     60 -   The function does **not** throw when provided `null` or `undefined`. Instead, the function returns `false`.
     61 
     62     ```javascript
     63     var bool = isMethodIn( null, 'toString' );
     64     // returns false
     65 
     66     bool = isMethodIn( void 0, 'toString' );
     67     // returns false
     68     ```
     69 
     70 -   Value arguments other than `null` or `undefined` are coerced to `objects`.
     71 
     72     ```javascript
     73     var bool = isMethodIn( 'beep', 'toString' );
     74     // returns true
     75     ```
     76 
     77 -   Non-symbol property arguments are coerced to `strings`.
     78 
     79     ```javascript
     80     function noop() {
     81         // Example function...
     82     }
     83 
     84     var value = {
     85         'null': noop
     86     };
     87     var bool = isMethodIn( value, null );
     88     // returns true
     89 
     90     value = {
     91         '[object Object]': noop
     92     };
     93     bool = isMethodIn( value, {} );
     94     // returns true
     95     ```
     96 
     97 </section>
     98 
     99 <!-- /.notes -->
    100 
    101 <section class="examples">
    102 
    103 ## Examples
    104 
    105 <!-- eslint-disable object-curly-newline, object-curly-spacing -->
    106 
    107 <!-- eslint no-undef: "error" -->
    108 
    109 ```javascript
    110 var isMethodIn = require( '@stdlib/assert/is-method-in' );
    111 
    112 var bool = isMethodIn( {}, 'toString' );
    113 // returns true
    114 
    115 bool = isMethodIn( { 'a': 'b' }, 'a' );
    116 // returns false
    117 
    118 bool = isMethodIn( { 'a': 'b' }, 'c' );
    119 // returns false
    120 
    121 bool = isMethodIn( { 'a': 'b' }, null );
    122 // returns false
    123 
    124 bool = isMethodIn( null, 'a' );
    125 // returns false
    126 
    127 bool = isMethodIn( void 0, 'a' );
    128 // returns false
    129 
    130 bool = isMethodIn( { 'null': isMethodIn }, null );
    131 // returns true
    132 
    133 bool = isMethodIn( { '[object Object]': isMethodIn }, {} );
    134 // returns true
    135 ```
    136 
    137 </section>
    138 
    139 <!-- /.examples -->
    140 
    141 <section class="links">
    142 
    143 </section>
    144 
    145 <!-- /.links -->