Created
November 5, 2012 02:56
-
-
Save rainyjune/4015059 to your computer and use it in GitHub Desktop.
JavaScript Object Property Attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Javascript</title> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var a={ | |
x:1, | |
y:2, | |
get z(){ | |
return this.x+this.y; | |
}, | |
set z(v){ | |
var ratio=v/(this.x+this.y); | |
this.x *= ratio; | |
this.y *= ratio; | |
} | |
}; | |
console.log(Object.getOwnPropertyDescriptor(a,'x'));//{value: 1, writable:true, enumerable:true, configurable:true} | |
console.log(Object.getOwnPropertyDescriptor(a,'z'));//{ get: /*func*/, set:/*func*/, enumerable:true, configurable:true} | |
console.log(Object.getOwnPropertyDescriptor(a,'toString'));//=>undefined | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment