Guest User

Untitled

a guest
Jan 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. var Patterns = {};
  2.  
  3. Patterns.Nokia = function(){
  4. this.getPrice = function(){
  5. return 200;
  6. };
  7. };
  8.  
  9. Patterns.Motorola = function(){
  10. this.getPrice = function(){
  11. return 100;
  12. };
  13. };
  14.  
  15. Patterns.PhoneFactory = {
  16. getPhone : function(type){
  17. switch(type){
  18. case "Motorola":
  19. return new Patterns.Motorola();
  20. case "Nokia":
  21. default:
  22. return new Patterns.Nokia();
  23. }
  24. }
  25. };
  26.  
  27. var phone = Patterns.PhoneFactory.getPhone("Nokia");
  28. console.log(phone.getPrice());
Add Comment
Please, Sign In to add comment