time-to-botec

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

README.md (3499B)


      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 # isWriteOnlyPropertyIn
     22 
     23 > Test if an object's own or inherited property is [write-only][@stdlib/utils/define-write-only-accessor].
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var isWriteOnlyPropertyIn = require( '@stdlib/assert/is-write-only-property-in' );
     31 ```
     32 
     33 #### isWriteOnlyPropertyIn( value, property )
     34 
     35 Returns a `boolean` indicating if a `value` has a [write-only][@stdlib/utils/define-write-only-accessor] `property`.
     36 
     37 <!-- eslint-disable no-restricted-syntax -->
     38 
     39 ```javascript
     40 var defineProperty = require( '@stdlib/utils/define-property' );
     41 
     42 var bool;
     43 var obj;
     44 
     45 function Foo() {
     46     this.foo = 'bar';
     47     return this;
     48 }
     49 
     50 defineProperty( Foo.prototype, 'beep', {
     51     'configurable': false,
     52     'enumerable': false,
     53     'writable': false,
     54     'value': 'boop'
     55 });
     56 
     57 defineProperty( Foo.prototype, 'accessor', {
     58     'configurable': false,
     59     'enumerable': true,
     60     'set': function setter( v ) {
     61         obj.foo = v;
     62     }
     63 });
     64 
     65 obj = new Foo();
     66 
     67 bool = isWriteOnlyPropertyIn( obj, 'foo' );
     68 // returns false
     69 
     70 bool = isWriteOnlyPropertyIn( obj, 'beep' );
     71 // returns false
     72 
     73 bool = isWriteOnlyPropertyIn( obj, 'accessor' );
     74 // returns true
     75 ```
     76 
     77 </section>
     78 
     79 <!-- /.usage -->
     80 
     81 <section class="notes">
     82 
     83 ## Notes
     84 
     85 -   Value arguments other than `null` or `undefined` are coerced to `objects`.
     86 
     87     ```javascript
     88     var bool = isWriteOnlyPropertyIn( 'beep', 'length' );
     89     // returns false
     90     ```
     91 
     92 -   Property arguments are coerced to `strings`.
     93 
     94     ```javascript
     95     var defineProperty = require( '@stdlib/utils/define-property' );
     96 
     97     var obj = {};
     98 
     99     function setter( v ) {
    100         obj.null = v;
    101     }
    102 
    103     defineProperty( obj, 'null', {
    104         'configurable': false,
    105         'enumerable': true,
    106         'set': setter
    107     });
    108 
    109     var bool = isWriteOnlyPropertyIn( obj, null );
    110     // returns true
    111     ```
    112 
    113 </section>
    114 
    115 <!-- /.notes -->
    116 
    117 <section class="examples">
    118 
    119 ## Examples
    120 
    121 <!-- eslint-disable object-curly-newline -->
    122 
    123 <!-- eslint no-undef: "error" -->
    124 
    125 ```javascript
    126 var isWriteOnlyPropertyIn = require( '@stdlib/assert/is-write-only-property-in' );
    127 
    128 var bool = isWriteOnlyPropertyIn( 'a', 'length' );
    129 // returns false
    130 
    131 bool = isWriteOnlyPropertyIn( { 'a': 'b' }, 'a' );
    132 // returns false
    133 
    134 bool = isWriteOnlyPropertyIn( [ 'a' ], 0 );
    135 // returns false
    136 
    137 bool = isWriteOnlyPropertyIn( { 'null': false }, null );
    138 // returns false
    139 
    140 bool = isWriteOnlyPropertyIn( { '[object Object]': false }, {} );
    141 // returns false
    142 
    143 bool = isWriteOnlyPropertyIn( {}, 'toString' );
    144 // returns false
    145 
    146 bool = isWriteOnlyPropertyIn( {}, 'hasOwnProperty' );
    147 // returns false
    148 
    149 bool = isWriteOnlyPropertyIn( null, 'a' );
    150 // returns false
    151 
    152 bool = isWriteOnlyPropertyIn( void 0, 'a' );
    153 // returns false
    154 ```
    155 
    156 </section>
    157 
    158 <!-- /.examples -->
    159 
    160 <section class="links">
    161 
    162 [@stdlib/utils/define-write-only-accessor]: https://www.npmjs.com/package/@stdlib/utils-define-write-only-accessor
    163 
    164 </section>
    165 
    166 <!-- /.links -->