-
Notifications
You must be signed in to change notification settings - Fork 0
Private Store
Malexion edited this page Nov 6, 2016
·
3 revisions
Wrapper for weakmap private class variables.
var store = new __.lib.PrivateStore();
var Shape = __.class(function(type) {
// bind to init store for new class, second param is optional for initial privates
store.bind(this, {
type: '',
info: {
points: -1
}
});
// access all privates with store.context
store.context(this, function(private) {
private.type = type;
private.info.points = 0;
});
}, {
type: {
get: function() {
return store.get(this, 'type'); // Easy getter will follow the path chain to your property
},
set: function(value) {
// Easy setter will follow the path chain to set your property and init empty objects along the way if it has to.
store.set(this, 'type', value);
}
},
points: {
get: function() {
return store.get(this, 'info.points');
},
set: function(value) {
store.set(this, 'info.points', value);
}
}
});