CurrentUser = function (){}
CurrentUser.prototype = {
record: undefined
}
CurrentUser.prototype.is = {
get _parent() {return CurrentUser.prototype},
get signedIn() {
return !!this._parent.record
}
}
User = new CurrentUser
User.record = {name:'Joe'}
User.is.signedIn //false
What I'm trying to do here is create a new User, give him some data (record) and based on that determine that he is signedIn (if his record has data - he is signedIn).
But what happens in reality is that User.is.signedIn
getter is accessing CurrentUser.prototype
instead of accessing User
instance. And as CurrentUser.prototype.record
is undefined
- User.is.signedIn
returns false
.