Skip to content

Objects created by userFactory can access sharePublicMessage method #4

@abhaasgoyal

Description

@abhaasgoyal

cs-bin-solutions/oop.js

Lines 181 to 188 in 20de7d4

function adminFactory(name, score) {
const admin = new userFactory(name, score);
admin.type = 'Admin';
return admin;
}
/* Put code here for a method called sharePublicMessage*/
userFunctionStore.sharePublicMessage = () => console.log('Welcome users!');

Above issue is with respect to Extension Question for - http://csbin.io/oop
The code does not prevent userFactory to access sharePublicMessage method.. Instead the solution should be to use Object.create in adminFactory function:

function adminFactory(name, score) {
  // Put code here
  let newAdminObj = userFactory(name,score);
  newAdminObj = Object.create(adminFunctionStore);
  newAdminObj.type = "Admin";
  return newAdminObj;
}

// Put code here for a method called sharePublicMessage

adminFunctionStore.sharePublicMessage = () => console.log("Welcome users!")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions