Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4504585
test_define_property.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
977 B
Referenced Files
None
Subscribers
None
test_define_property.js
View Options
// Test Object.defineProperty()
const
object
=
{};
Object
.
defineProperty
(
object
,
"foo"
,
{
value
:
42
,
writable
:
false
,
});
console
.
log
(
"object.foo ="
,
object
.
foo
);
// Try to modify (should be prevented by configurable: false default)
try
{
object
.
foo
=
77
;
console
.
log
(
"After trying to modify, object.foo ="
,
object
.
foo
);
}
catch
(
e
)
{
console
.
log
(
"Cannot modify foo (expected):"
,
e
);
}
// Test with enumerable
const
obj2
=
{};
Object
.
defineProperty
(
obj2
,
"bar"
,
{
value
:
"hello"
,
enumerable
:
true
,
configurable
:
true
});
console
.
log
(
"obj2.bar ="
,
obj2
.
bar
);
console
.
log
(
"Object.keys(obj2) ="
,
Object
.
keys
(
obj2
));
// Test with non-enumerable property
const
obj3
=
{};
Object
.
defineProperty
(
obj3
,
"hidden"
,
{
value
:
"secret"
,
enumerable
:
false
});
obj3
.
visible
=
"public"
;
console
.
log
(
"obj3.hidden ="
,
obj3
.
hidden
);
console
.
log
(
"obj3.visible ="
,
obj3
.
visible
);
console
.
log
(
"Object.keys(obj3) ="
,
Object
.
keys
(
obj3
));
console
.
log
(
"All tests passed!"
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, May 3, 9:54 AM (3 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
523540
Default Alt Text
test_define_property.js (977 B)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment