time-to-botec

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

builtin.js (3002B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MAIN //
     22 
     23 /**
     24 * Defines (or modifies) an object property.
     25 *
     26 * ## Notes
     27 *
     28 * -   Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.
     29 *
     30 * @name defineProperty
     31 * @type {Function}
     32 * @param {Object} obj - object on which to define the property
     33 * @param {(string|symbol)} prop - property name
     34 * @param {Object} descriptor - property descriptor
     35 * @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object
     36 * @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties
     37 * @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator
     38 * @param {*} [descriptor.value] - property value
     39 * @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.
     40 * @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.
     41 * @throws {TypeError} first argument must be an object
     42 * @throws {TypeError} third argument must be an object
     43 * @throws {Error} property descriptor cannot have both a value and a setter and/or getter
     44 * @returns {Object} object with added property
     45 *
     46 * @example
     47 * var obj = {};
     48 *
     49 * defineProperty( obj, 'foo', {
     50 *     'value': 'bar'
     51 * });
     52 *
     53 * var str = obj.foo;
     54 * // returns 'bar'
     55 */
     56 var defineProperty = Object.defineProperty;
     57 
     58 
     59 // EXPORTS //
     60 
     61 module.exports = defineProperty;