Adds properties to an object, or modifies attributes of existing properties.
defineProperties(object, properties)
object
Object on which to add or modify the properties.
properties
Object that contains one or more descriptor objects.
The object that was passed to the function.
let obj = {}
Object.defineProperties(obj, {
speed: {
value: 120,
writable: true
},
unit: {
value: "mph",
writable: false
}
});
`${obj.speed} ${obj.unit}`
"120 mph"