Returns a property descriptor for the specified property of the specified object
Javascript இல் Object.getOwnPropertyDescriptor() method இங்கு ஒரு object க்கு உரிய enumerable property இன் முழு information தருகிறது. அதாவது இந்த function ஒரு object property இன் descriptor ஐ நமக்கு return செய்கிறது
JavaScript Object.getOwnPropertyDescriptor() Method
Javascript இல் Object.getOwnPropertyDescriptor() method இங்கு ஒரு object க்கு உரிய enumerable property இன் முழு information தருகிறது. அதாவது இந்த function ஒரு object property இன் descriptor ஐ நமக்கு return செய்கிறது.
Object.getOwnPropertyDescriptor(bird,"name")
Example1
<script>
const bird = {
name:"peacock"
};
var res = Object.getOwnPropertyDescriptor(bird,"name");
document.writeln(res.enumerable);
document.writeln(res.value);
</script>
மேலே உள்ள Example1-ஐ கவனிக்கவும் இங்கு Object.getOwnPropertyDescriptor() method இல் bird object மற்றும் property name ஆனது argument ஆக அனுபப்படுகிறது. இங்கு name property இன் descriptor value ஆனது ஒரு object ஆக கிடைக்கிறது அவைகள் முறையே {value: 'peacock', writable: true, enumerable: true, configurable: true} என்ற நான்கு properties கள் கிடைக்கிறது. எனவே நமக்கு output true,peacock என கிடைக்கிறது.
true peacock
Example2
<script>
const animal = {
first:"tiger"
};
var res = Object.getOwnPropertyDescriptor(animal,"first");
document.writeln(res.enumerable);
document.writeln(res.value);
</script>
மேலே உள்ள Example2-ஐ கவனிக்கவும் இங்கு Object.getOwnPropertyDescriptor() method இல் animal object மற்றும் property name first என்பது argument ஆக அனுபப்படுகிறது. இங்கு first என்ற property இன் descriptor value ஆனது ஒரு object ஆக கிடைக்கிறது அவைகள் முறையே {value: 'tiger', writable: true, enumerable: true, configurable: true} என்ற நான்கு properties கள் கிடைக்கிறது. எனவே நமக்கு output true,tiger என கிடைக்கிறது.
true tiger