Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function objectfactory(library, orders){
- let result = []
- orders.forEach(temp => {
- let newObject = Object.assign({}, temp.template)
- for (let parts of temp.parts){
- newObject[parts] = library[parts]
- }
- result.push(newObject)
- });
- return result
- }
- const library = {
- print: function () {
- console.log(`${this.name} is printing a page`);
- },
- scan: function () {
- console.log(`${this.name} is scanning a document`);
- },
- play: function (artist, track) {
- console.log(`${this.name} is playing '${track}' by ${artist}`);
- },
- };
- const orders = [
- {
- template: { name: 'ACME Printer'},
- parts: ['print']
- },
- {
- template: { name: 'Initech Scanner'},
- parts: ['scan']
- },
- {
- template: { name: 'ComTron Copier'},
- parts: ['scan', 'print']
- },
- {
- template: { name: 'BoomBox Stereo'},
- parts: ['play']
- }
- ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement