Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function MemberFactory(){
- this.createMember = function(name, type) {
- let member;
- if(type === "simple"){
- member = new SimpleMembership(name)
- }
- if(type === "standard"){
- member = new StandardMembership(name)
- }
- if(type === "super"){
- member = new SuperMembership(name)
- }
- member.type = type;
- member.define = function(){
- console.log(`${this.name} (${this.type}): ${this.cost}`)
- }
- return member
- }
- }
- constr SimpleMembership = function(name){
- this.name = name;
- this.cost = `$5`;
- }
- const StandardMembership = function(name){
- this.name = name;
- this.cost = `$15`
- }
- const SuperMembership = function(name){
- this.name = name;
- this.cost = `$25`;
- }
- const members = [];
- const factory = new MemberFactory();
- members.push(factory.createMember(`John Doe`, `simple`));
- members.push(factory.createMember(`Bob John`, `standard`));
- members.push(factory.createMember(`Israel Love`, `super`));
- //this below uses a function which will console.log name-type, u can also console.log member
- members.forEach(function(members){
- members.define()
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement