Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Patterns = {};
- Patterns.Nokia = function(){
- this.getPrice = function(){
- return 200;
- };
- };
- Patterns.Motorola = function(){
- this.getPrice = function(){
- return 100;
- };
- };
- Patterns.PhoneFactory = {
- getPhone : function(type){
- switch(type){
- case "Motorola":
- return new Patterns.Motorola();
- case "Nokia":
- default:
- return new Patterns.Nokia();
- }
- }
- };
- var phone = Patterns.PhoneFactory.getPhone("Nokia");
- console.log(phone.getPrice());
Add Comment
Please, Sign In to add comment