You are reading a single comment by @d0773d and its replies.
Click here to read the full conversation.
-
Hi @Gordon The reason why I chose
Sensor.prototype = {
was, at the time, I didn't care for the repetitiveness of writingSensor.prototype.
However, thats nothing that copy and paste can't fix :). As you recommended, I switched toSensor.prototype.getSensorType = function
. I can appreciate the readability and the code seems to flow a little better and makes sense to me.
The structure looks pretty tidy - although I'd really recommend doing:
Instead of your
Sensor.prototype = {
. It's probably more personal opinion, but it seems more pleasant than having to redefineconstructor
.You've also defined getters like
getSensorAddress
, which is fine - however you then doa = this.getSensorAddress;
. That'll return the function itself, rather than executing it and getting the result... You might also want to put avar
beforea
, soa
isn't defined as a global variable.In your code
getSensorResult
returns immediately, so while you get a value ingetSensorReading
you're not actually returning it. For that, you'd need to use a callback:Then you can use it with:
Hope that helps!