You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
functionadminFactory(name,score){// Put code hereletnewAdminObj=userFactory(name,score);newAdminObj=Object.create(adminFunctionStore);newAdminObj.type="Admin";returnnewAdminObj;}// Put code here for a method called sharePublicMessageadminFunctionStore.sharePublicMessage=()=>console.log("Welcome users!")
The text was updated successfully, but these errors were encountered:
@abhaasgoyal You are right saying that the userFactory have access to sharePublicMessage. But your solution is incorrect, you override the newAdminObj. This new object now doesn't have the properties of userFactory (Both name and score will be undefined).
// This part is right:adminFunctionStore.sharePublicMessage=()=>console.log("Welcome users!")
Correct me if I'm wrong here, but the correct way should be to have both prototypes accessible to the object returned by the adminFactory. The way I did it was to create an object with the admin prototype, merge them and assign the new object as the new prototype of the returned object. This way we have all the methods in both function stores and the properties defined in userFactory.
cs-bin-solutions/oop.js
Lines 181 to 188 in 20de7d4
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:
The text was updated successfully, but these errors were encountered: