Let's say I want a provider to request a file
// Create the Provider
const Provider = function(datas) {
if(!datas || !datas.provider) console.warn('Nope, need a provider')
const { provider } = datas;
this.provider = provider;
}
// Attach a function to the Provider
Provider.prototype.requestFile = function(informations) {
if (informations) {
console.log(`Le provider est ${this.provider}`);
return console.log(`Bonjour, je demande le fichier avec ${JSON.stringify(informations)}`);
}
return console.warn('Need informations to request the file');
}
// Instanciate the Provider
const P = new Provider({ provider: 'google'})
const M = new Provider({ provider: 'duckduckgo'})
// Use the Provider's requests
P.requestFile({ name: "toto" })
M.requestFile({ name: "toto" })
module.exports = Provider;
More here : https://youtu.be/hS_WqkyUah8?t=7m41s