-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Singletonable mixin #3
Conversation
varargs = arguments._.tail(); | ||
|
||
// Storage for the the singleton object, once it is created | ||
var singleton; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally I think this would be Constructor._singleton or something like that so that people could mock/override it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... I guess that won't really work because of the name you're using, but you could provide a setter method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a previous iteration, I had set configurable: true, thinking that would make it so subclasses could override it. But then I realized that that's not necessary for the subclass case, and took it off. Mocking is a good point though, so I think you're right.
I have a trick for this kind of situation where you define a property as a configurable property, but then set it when it's accessed, so it acts exactly like normal property. That'll be good because then we can use autoMock too.
delete object[name]; | ||
object[name] = value; | ||
return value; | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I just realized this also needs a setter, or you won't be able to set it if it's never been accessed.
No description provided.