How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 06-06-redefine-read-only-props.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  4. 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) 
} 
  1. 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)}
  1. Attempt to redefine the property a third time:

 export function main() { 
  // ... 
  // throws error
Object.defineProperty(obj, 'prop1',{
value: Math.random()
}); }
  1. Start your Python web server and open the following link in your browser:
    http://localhost:8000/.
  2. You should see the following output displayed:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.13.129