- Open your command-line application and navigate to your workspace.
- Create a new folder named 06-06-redefine-read-only-props.
- Copy or create an index.html that loads and runs a main function from main.js.
- Create a main.js file with a main function that creates an object. Define a configurable, non-writable property named prop1 with a random value:
export function main() { const obj = {}; Object.defineProperty(obj, 'prop1',{ writable: false, configurable: true, value: Math.random() }); console.log(obj.prop1) }
- Redefine that property as another random value and change configurable to false:
export function main() { // ... Object.defineProperty(obj, 'prop1',{
writable: false,
configurable: false,
value: Math.random()
});
console.log(obj.prop1)}
-
Attempt to redefine the property a third time:
export function main() { // ... // throws error
Object.defineProperty(obj, 'prop1',{
value: Math.random()
}); }
- Start your Python web server and open the following link in your browser:
http://localhost:8000/. - You should see the following output displayed: