forked from nkronlage/JavaScripture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpropertydescriptor.jsdoc
More file actions
174 lines (140 loc) · 5.08 KB
/
Copy pathpropertydescriptor.jsdoc
File metadata and controls
174 lines (140 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
PropertyDescriptor : Object
A **PropertyDescriptor** describes a property on an %%/Object|**Object**%%.
Any JavaScript object can be used as a **PropertyDescriptor** where
unspecified properties will be treated as **undefined** or **false**.
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-8.10
----
instance.configurable : Boolean
Set to **true** if the property descriptor can be changed later.
See the %%/Object#freeze|**Object.freeze()**%%
and %%/Object#seal|**Object.seal()**%%
methods for ways to set configurable to false on all properties on
an object.
<example>
var x = {};
Object.defineProperty(x, 'foo', { value: 1,
writable: false,
enumerable: true,
configurable: false } );
try {
// Attempt to override non-configurable property descriptor
Object.defineProperty(x, 'foo', { value: 1,
writable: true,
enumerable: true,
configurable: false } );
} catch(e) {
console.log('Error:');
console.log(e);
}
</example>
----
instance.enumerable : Boolean
Set to **true** if the property is accessed during
**for (propertyName in object)**.
See the %%/Object#propertyIsEnumerable|**Object.propertyIsEnumerable()**%%
method.
<example>
var x = { foo: 1 };
Object.defineProperty(x, 'bar', { value: 2,
writable: true,
enumerable: false,
configurable: true } );
// 'foo' is enumerable. 'bar' in not enumerable
for (var propertyName in x) {
console.log(propertyName + ' is ' + x[propertyName]);
}
</example>
----
instance.get : getFunction() : Object
The getter function that returns the value for the property.
Use %%#set|**set**%% to specified the setter function.
If **get** or %%#set|**set**%%
functions are specified, %%#value|**value**%% and %%#writable|**writable**%%
cannot be specified.
<example>
var x = { get foo() {
console.log('in x.foo getter');
return this._foo;
},
set foo(value) {
console.log('in x.foo setter. value = ' + value);
this._foo = value;
}
};
console.log('setting x.foo to 1');
x.foo = 1;
console.log('getting x.foo');
console.log(x.foo);
// Equivalent definition of 'foo' using a PropertyDescriptor
var y = {};
Object.defineProperty(y, 'foo', { get: function() {
console.log('in y.foo getter');
return this._foo;
},
set: function() {
console.log('in y.foo setter. value = ' + value);
return this._foo;
},
enumerable: true,
configurable: true } );
</example>
----
instance.set : setFunction(value : Object) : undefined
The setter function that is called when setting the property.
Use %%#get|**get**%% to specified the getter function.
If **get** or %%#set|**set**%% functions are specified,
%%#value|**value**%% and %%#writable|**writable**%% cannot be specified.
<example>
var x = { get foo() {
console.log('in x.foo getter');
return this._foo;
},
set foo(value) {
console.log('in x.foo setter. value = ' + value);
this._foo = value;
}
};
console.log('setting x.foo to 1');
x.foo = 1;
console.log('getting x.foo');
console.log(x.foo);
// Equivalent definition of 'foo' using a PropertyDescriptor
var y = {};
Object.defineProperty(y, 'foo', { get: function() {
console.log('in y.foo getter');
return this._foo;
},
set: function() {
console.log('in y.foo setter. value = ' + value);
return this._foo;
},
enumerable: true,
configurable: true } );
</example>
----
instance.value : Object
The value stored in the property. **value** can only be specified
if both %%#get|**get**%% and %%#set|**set**%% functions are not specified.
<example>
var x = { foo: 1 };
Object.defineProperty(x, 'bar', { value: 2, enumerable: true } );
for (var propertyName in x) {
console.log(propertyName + ' value is ' + x[propertyName]);
}
</example>
----
instance.writable : Boolean
Set to **true** if the property can be modified, **false** otherwise.
**writable** can only be specified
if both %%#get|**get**%% and %%#set|**set**%% functions are not specified.
<example>
var x = { foo: 1 };
Object.defineProperty(x, 'bar', { value: 2,
writable: false } );
x.foo = 1234;
console.log(x.foo);
// bar is not writable. Setting it silently fails.
x.bar = 1234;
console.log(x.bar);
</example>