Skip to content

Latest commit

 

History

History
93 lines (73 loc) · 2.91 KB

File metadata and controls

93 lines (73 loc) · 2.91 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
Object.getOwnPropertyDescriptor Function (JavaScript) | Microsoft Docs
01/18/2017
windows-client-threshold
devlang-javascript
language-reference
JavaScript
TypeScript
DHTML
getOwnPropertyDescriptor method [JavaScript]
8f0e1c90-c4f9-44c4-bf76-726bacecbc14
45
mikejo5000
mikejo
ghogen

Object.getOwnPropertyDescriptor Function (JavaScript)

Gets the own property descriptor of the specified object. An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype.

Syntax

Object.getOwnPropertyDescriptor(object, propertyname)  

Parameters

object
Required. The object that contains the property.

propertyname
Required. The name of the property.

Return Value

The descriptor of the property.

Remarks

You can use the Object.getOwnPropertyDescriptor function to obtain a descriptor object that describes attributes of the property.

The Object.defineProperty Function is used to add or modify properties.

Data Property Example

The following example gets a data property descriptor and uses it to make the property read-only.

// Create a user-defined object.  
var obj = {};  
  
// Add a data property.  
obj.newDataProperty = "abc";  
  
// Get the property descriptor.  
var descriptor = Object.getOwnPropertyDescriptor(obj, "newDataProperty");  
  
// Change a property attribute.  
descriptor.writable = false;  
Object.defineProperty(obj, "newDataProperty", descriptor);  
  

To list the property attributes, you can add the following code to this example.

// Get the descriptor from the object.  
var desc2 = Object.getOwnPropertyDescriptor(obj, "newDataProperty");  
  
// List the descriptor attributes.  
for (var prop in desc2) {  
    document.write(prop + ': ' + desc2[prop]);  
    document.write("<br />");  
}  
  
// Output:  
// value: abc  
// writable: false  
// enumerable: true  
// configurable: true  

Requirements

All features are supported in [!INCLUDEjsv9text].

[!INCLUDEjsv58textspecific] supports DOM objects but not user-defined objects. The enumerable and configurable attributes can be specified, but they are not used.

See Also

Document Object Model Prototypes, Part 2: Accessor (getter/setter) Support
Object.defineProperty Function