var obj = {
prop: function () {},
foo: "bar"
};
// New properties may be added, existing properties may be changed or removed
obj.foo = "baz";
obj.lumpy = "woof";
delete obj.prop;
var o = Object.seal(obj);
console.log(o === obj);
console.log(Object.isSealed(obj) === true);
// Changing property values on a sealed object still works.
obj.foo = "quux";
// But you can't convert data properties to accessors, or vice versa.
Object.defineProperty(obj, "foo", { get: function() { return "g"; } }); // throws a TypeError
// Now any changes, other than to property values, will fail.
obj.quaxxor = "the friendly duck"; // silently doesn't add the property
delete obj.foo; // silently doesn't delete the property
// ...and in strict mode such attempts will throw TypeErrors
function fail() {
"use strict";
delete obj.foo; // throws a TypeError
obj.sparky = "arf"; // throws a TypeError
}
fail();
// Attempted additions through Object.defineProperty will also throw
Object.defineProperty(obj, "ohai", { value: 17 }); // throws a TypeError
Object.defineProperty(obj, "foo", { value: "eit" }); // changes existing property value
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.