Skip to content

Instantly share code, notes, and snippets.

@rainyjune
Created November 5, 2012 02:56
Show Gist options
  • Save rainyjune/4015059 to your computer and use it in GitHub Desktop.
Save rainyjune/4015059 to your computer and use it in GitHub Desktop.
JavaScript Object Property Attributes
<!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