Coding standards - damoclark/buzzer.click GitHub Wiki
Getter/Setters (Accessors/Mutators)
Note: because a missing getter or setter doesn't throw an error, if you define a readonly or write-only property you should also throw an error for incorrect usage.
/**
* Defines a property to get a flag for whether the participant is connected or disconnected
* @readonly
* @throws on set value
* @return True when the participant is disconnected; else, false.
*/
Object.defineProperty(Participant.prototype, 'isDisconnected', {
get: function() {
return this._disconnected;
},
/* eslint-disable no-unused-vars */
set: function(val) {
/* eslint-enable no-unused-vars */
throw new Error('Property is readonly.');
}
});
/**
* Defines a property to get or set a flag for whether the participant is connected or disconnected
* @return True when the participant is disconnected; else, false.
*/
Object.defineProperty(Participant.prototype, 'isDisconnected', {
get: function() {
return this._disconnected;
},
set: function(val) {
this._disconnected = val;
}
});
/**
* Defines a property to set a flag for whether the participant is connected or disconnected
* @throws on get value
*/
Object.defineProperty(Participant.prototype, 'isDisconnected', {
get: function() {
throw new Error('Property is write only.');
},
set: function(val) {
this._disconnected = val;
}
});
Private fields and methods
A private field and method should start with an _
(underscore). This allows for the easy identification of the intended access limitation and to also avoid names clashing when a field access is via a property.
Participant.prototype._id = null;
/**
* Defines a property to get or set a flag for whether the participant is connected or disconnected
* @return True when the participant is disconnected; else, false.
*/
Object.defineProperty(Participant.prototype, 'id', {
get: function() {
return this._id;
},
set: function(val) {
this._id = val;
}
});
Participant.prototype._counter = 0;
Participant.prototype._incrementCounter = function() {
this._counter++;
}