README.md (1974B)
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 # Non-Enumerable Read-Only 22 23 > [Define][@stdlib/utils/define-property] a non-enumerable **read-only** property. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); 31 ``` 32 33 #### setNonEnumerableReadOnly( obj, prop, value ) 34 35 [Defines][@stdlib/utils/define-property] a non-enumerable **read-only** property. 36 37 <!-- run throws: true --> 38 39 ```javascript 40 var obj = {}; 41 42 setNonEnumerableReadOnly( obj, 'foo', 'bar' ); 43 44 obj.foo = 'boop'; 45 // throws <Error> 46 ``` 47 48 </section> 49 50 <!-- /.usage --> 51 52 <section class="notes"> 53 54 ## Notes 55 56 - Non-enumerable read-only properties are **non-configurable**. 57 58 </section> 59 60 <!-- /.notes --> 61 62 <section class="examples"> 63 64 ## Examples 65 66 <!-- eslint no-undef: "error" --> 67 68 ```javascript 69 var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); 70 71 function Foo( name ) { 72 if ( !(this instanceof Foo) ) { 73 return new Foo( name ); 74 } 75 setNonEnumerableReadOnly( this, 'name', name ); 76 return this; 77 } 78 79 var foo = new Foo( 'beep' ); 80 81 try { 82 foo.name = 'boop'; 83 } catch ( err ) { 84 console.error( err.message ); 85 } 86 ``` 87 88 </section> 89 90 <!-- /.examples --> 91 92 <section class="links"> 93 94 [@stdlib/utils/define-property]: https://www.npmjs.com/package/@stdlib/utils/tree/main/define-property 95 96 </section> 97 98 <!-- /.links -->