How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 06-04-define-function-properties-as-method.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  4. Create a main.js with a function named main that defines two methods with the property and method syntax, overrides them, and calls them before and after override:
// main.js  
export function main() { 
     const obj = { 
    method0: function() { 
      console.log('Hello, from method one.') 
    }, 
       method1() { 
      console.log('Hello, from method one.') 
    } 
  }; 
  obj.method0(); 
  obj.method1(); 
 
  obj.method0 = () => console.log('Override of method 0.'); 
  obj.method1 = () => console.log('Override of method 1.'); 
  obj.method0(); 
  obj.method1(); 
}   
  1. Start your Python web server and open the following link in your browser:
    http://localhost:8000/.
  1. 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
3.17.29.19