The static method 2 defines a new property directly on an object, or modifies an existing property on an object, and returns the object. Show
3The object on which to define the property. 4The name or 5 of the property to be defined or modified. 6The descriptor for the property being defined or modified. The object that was passed to the function. This method allows a precise addition to or modification of a property on an object. Normal property addition through assignment creates properties which show up during property enumeration ( 7 loop or 8 method), whose values may be changed, and which may be deleted. This method allows these extra details to be changed from their defaults. By default, properties added using 2 are not writable, not enumerable, and not configurable.Property descriptors present in objects come in two main 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 pair of functions. A descriptor must be one of these two flavors; it cannot be both. Both data and accessor descriptors are objects. They share the following optional keys (please note: the defaults mentioned here are in the case of defining properties using 2): 1when this is set to 2,
Defaults to 2. 8 9 if and only if this property shows up during enumeration of the properties on the corresponding object. Defaults to 2.A data descriptor also has the following optional keys: 4The value associated with the property. Can be any valid JavaScript value (number, object, function, etc.). Defaults to 2. 5 9 if the value associated with the property may be changed with an . Defaults to 2.An accessor descriptor also has the following optional keys: 6A function which serves as a getter for the property, or 2 if there is no getter. When the property is accessed, this function is called without arguments and with 8 set to the object through which the property is accessed (this may not be the object on which the property is defined due to inheritance). The return value will be used as the value of the property. Defaults to 2. 0A function which serves as a setter for the property, or 2 if there is no setter. When the property is assigned, this function is called with one argument (the value being assigned to the property) and with 8 set to the object through which the property is assigned. Defaults to 2.If a descriptor has neither of 4, 5, 6 and 0 keys, it is treated as a data descriptor. If a descriptor has both [ 4 or 5] and [ 6 or 0] keys, an exception is thrown.Bear in mind that these attributes are not necessarily the descriptor's own properties. Inherited properties will be considered as well. In order to ensure these defaults are preserved, you might freeze existing objects in the descriptor object's prototype chain upfront, specify all options explicitly, or point to 2 with 3.
When the property already exists, 2 attempts to modify the property according to the values in the descriptor and the property's current configuration.If the old descriptor had its 1 attribute set to 2, the property is said to be non-configurable. It is not possible to change any attribute of a non-configurable accessor property, and it is not possible to switch between data and accessor property types. For data properties with 3, it is possible to modify the value and change the 5 attribute from 9 to 2. A 1 is thrown when attempts are made to change non-configurable property attributes (except 4 and 5, if permitted), except when defining a value same as the original value on a data property.When the current property is configurable, defining an attribute to 2 effectively deletes it. For example, if 5 is an accessor property, 6 will remove the setter, making 7 only have a getter and become readonly. If an attribute is absent from the new descriptor, the old descriptor attribute's value is kept (it won't be implicitly re-defined to 2). It is possible to toggle between data and accessor property by giving a descriptor of a different "flavor". For example, if the new descriptor is a data descriptor (with 4 or 5), the original descriptor's 6 and 0 attributes will both be dropped.When the property specified doesn't exist in the object, 2 creates a new property as described. Fields may be omitted from the descriptor, and default values for those fields are inputted.
When modifying an existing property, the current property configuration determines if the operator succeeds, does nothing, or throws a 1.Writable attributeWhen the 5 property attribute is set to 2, the property is said to be "non-writable". It cannot be reassigned.
As seen in the example, trying to write into the non-writable property doesn't change it but doesn't throw an error either. Enumerable attributeThe 8 property attribute defines whether the property is picked by 8 or spread operator. For non- 5 properties it also defines whether it shows up in a 7 loop and 1 or not.
Configurable attributeThe 1 attribute controls at the same time whether the property can be deleted from the object and whether its attributes (other than 4 and 5) can be changed.When it is 2, but 5 is 9, 4 can still be changed, and 5 can still be toggled from 9 to 2; when it is 9, but 5 is 2, 4 may still be replaced with 6 (but not with assignment operators), and 5 may be toggled.
If the 1 attribute of 9 had been 9, none of the errors would be thrown and the property would be deleted at the end.It is important to consider the way default values of attributes are applied. There is often a difference between using dot notation to assign a value and using 2, as shown in the example below.
The example below shows how to implement a self-archiving object. When 02 property is set, the 03 array gets a log entry.
In this example, a getter always returns the same value.
If an accessor property is inherited, its 6 and 0 methods will be called when the property is accessed and modified on descendant objects. If these methods use a variable to store the value, this value will be shared by all objects.
This can be fixed by storing the value in another property. In 6 and 0 methods, 8 points to the object which is used to access or modify the property. 0Unlike accessor properties, value properties are always set on the object itself, not on a prototype. However, if a non-writable value property is inherited, it still prevents from modifying the property on the object. When a piece of data is read from a file?When a piece of data is read from a file, it is copied from the file into the program. Closing a file disconnects the communication between the file and the program. In Python, there is nothing that can be done if the program tries to access a file to read that does not exist.
What happens when a piece of data is written to a file?When a piece of data is written to a file, it is copied from a variable in RAM to the file. The process of retrieving data from a file is known as reading data from the file.
What is the process of retrieving data from a file called?Data extraction is the act or process of retrieving data out of (usually unstructured or poorly structured) data sources for further data processing or data storage (data migration).
What is a file's read position where is the read position when a file is first opened for reading?The Read position of a file is the location of the next item that will be read from a file. When a file is first opened for reading then by default the read position of the file will begin at the first character of the file.
|