Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Vendor A
- */
- VendorA = {};
- VendorA.title = function title() {
- return "Vendor A";
- };
- VendorA.pay = function pay(amount) {
- console.log(
- `setting up configuration using username: ${this.username} and password: ${
- this.password
- }`
- );
- return `Payment for service $${amount} is successful using ${this.title()}`;
- };
- /**
- *Vendor B
- */
- VendorB = {};
- VendorB.title = function title() {
- return "Vendor B";
- };
- VendorB.pay = function pay(amount) {
- console.log(
- `setting up configuration using username: ${this.username}
- and password: ${this.password}`
- );
- return `Payment for service $${amount} is successful using ${this.title()}`;
- };
- /**
- *
- * @param {*} vendorOption
- * @param {*} config
- */
- function VendorFactory(vendorOption, config = {}) {
- const vendor = Object.create(vendorOption);
- Object.assign(vendor, config);
- return vendor;
- }
- const vendorFactory = VendorFactory(VendorA, {
- username: "test",
- password: "1234"
- });
- console.log(vendorFactory.title());
- console.log(vendorFactory.pay(12));
- const vendorFactory2 = VendorFactory(VendorB, {
- username: "testTwo",
- password: "4321"
- });
- console.log(vendorFactory2.title());
- console.log(vendorFactory2.pay(50));
Add Comment
Please, Sign In to add comment