I am trying to create a class for serial port using Node.js,
But but I want to know isif there is a better way to write my data class code?.
In my sample code below, in the "getPortName"getPortName prototype in the forEachforEach loop, I declare a port object to store the serial port information before pushpushing into an array,.
Is this a good way of declaring this port object?
I think it is not good because it is difficult for users to see what the objectsobjects' members contain, is. Is there anywayany way to make it clearly expose the port object member?
Or there is there a better way to improve this code structure?
'use strict';
var serialPort = require("serialport");
function Serial() {
this.ComName = "";
}
Serial.prototype.getPortName = function() {
serialPort.list(function (err, ports) {
var availablePorts = [];
ports.forEach(function(port) {
var port = {
comName: "",
manufacturer: "",
pnpId:
}
port.comName = port.comName;
port.manufacturer = port.manufacturer;
port.pnpId = port.pnpId;
availablePorts.push(port);
});
});
return availablePorts;
};
Serial.prototype.setCOMName = function(name) {
this.ComName = name;
}
module.exports = Serial;