Guest User

Untitled

a guest
Oct 25th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. /**
  2. * Vendor A
  3. */
  4. VendorA = {};
  5.  
  6. VendorA.title = function title() {
  7. return "Vendor A";
  8. };
  9.  
  10. VendorA.pay = function pay(amount) {
  11. console.log(
  12. `setting up configuration using username: ${this.username} and password: ${
  13. this.password
  14. }`
  15. );
  16. return `Payment for service $${amount} is successful using ${this.title()}`;
  17. };
  18.  
  19. /**
  20. *Vendor B
  21. */
  22. VendorB = {};
  23. VendorB.title = function title() {
  24. return "Vendor B";
  25. };
  26.  
  27. VendorB.pay = function pay(amount) {
  28. console.log(
  29. `setting up configuration using username: ${this.username}
  30. and password: ${this.password}`
  31. );
  32. return `Payment for service $${amount} is successful using ${this.title()}`;
  33. };
  34.  
  35. /**
  36. *
  37. * @param {*} vendorOption
  38. * @param {*} config
  39. */
  40.  
  41. function VendorFactory(vendorOption, config = {}) {
  42. const vendor = Object.create(vendorOption);
  43. Object.assign(vendor, config);
  44. return vendor;
  45. }
  46.  
  47. const vendorFactory = VendorFactory(VendorA, {
  48. username: "test",
  49. password: "1234"
  50. });
  51. console.log(vendorFactory.title());
  52. console.log(vendorFactory.pay(12));
  53.  
  54. const vendorFactory2 = VendorFactory(VendorB, {
  55. username: "testTwo",
  56. password: "4321"
  57. });
  58. console.log(vendorFactory2.title());
  59. console.log(vendorFactory2.pay(50));
Add Comment
Please, Sign In to add comment