Advertisement
bebo231312312321

Untitled

Mar 20th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function objectfactory(library, orders){
  2. let result = []
  3. orders.forEach(temp => {
  4.     let newObject = Object.assign({}, temp.template)
  5.     for (let parts of temp.parts){
  6.         newObject[parts] = library[parts]
  7.     }
  8.     result.push(newObject)
  9. });
  10. return result
  11.  
  12. }
  13.  
  14. const library = {
  15.     print: function () {
  16.       console.log(`${this.name} is printing a page`);
  17.     },
  18.     scan: function () {
  19.       console.log(`${this.name} is scanning a document`);
  20.     },
  21.     play: function (artist, track) {
  22.       console.log(`${this.name} is playing '${track}' by ${artist}`);
  23.     },
  24.   };
  25.   const orders = [
  26.     {
  27.       template: { name: 'ACME Printer'},
  28.       parts: ['print']      
  29.     },
  30.     {
  31.       template: { name: 'Initech Scanner'},
  32.       parts: ['scan']      
  33.     },
  34.     {
  35.       template: { name: 'ComTron Copier'},
  36.       parts: ['scan', 'print']      
  37.     },
  38.     {
  39.       template: { name: 'BoomBox Stereo'},
  40.       parts: ['play']      
  41.     }
  42.   ];
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement