function robotFactory(model, mobile){ return { model, mobile, beep() { console.log('Beep Boop'); } } } // To check that the property value shorthand technique worked: const newRobot = robotFactory('P-501', false) console.log(newRobot.model) console.log(newRobot.mobile)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter