Metode JavaScript Object.getOwnPropertyDescriptors () atgriež visus konkrētā objekta īpašību aprakstus.
Metodes sintakse getOwnPropertyDescriptors()
ir šāda:
Object.getOwnPropertyDescriptors(obj)
getOwnPropertyDescriptors()
Metodi, kas ir statiska metode, sauc izmantojot Object
klases nosaukumu.
getOwnPropertyDescriptors () parametri
getOwnPropertyDescriptors()
Metode ņem in:
- obj - objekts, par kuru iegūt visus savus īpašuma aprakstus.
Atgriezties no getOwnPropertyDescriptors ()
- Atgriež objektu, kurā ir visi objekta īpašību deskriptori
Piemērs: getOwnPropertyDescriptors () izmantošana
let obj = ( x: 10, get number() ( return this.x; ), ); let value = Object.getOwnPropertyDescriptors(obj); console.log(value); // getOwnPropertyDescriptors() can be used for shallow clone let cloneObj = Object.create( Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj) ); console.log(cloneObj); // ( x: 10, number: (Getter) )
Rezultāts
(x: (vērtība: 10, rakstāms: patiess, uzskaitāms: patiess, konfigurējams: patiess), numurs: (iegūt: (funkcija: iegūt numuru), iestatīt: nenoteikts, uzskaitāms: patiess, konfigurējams: patiess)) (x: 10 , numurs: (Getter))
Ieteicamā literatūra: Javascript Object.getOwnPropertyDescriptor ()