Skip to main content
edited tags; edited title
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

JavaScript OOP structuring data class Serial port for Node.js

added 2 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Javascript JavaScript OOP structuring data class

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;

Javascript OOP structuring data class

I am trying to create a class for serial port using Node.js,

But I want to know is there a better way to write my data class code?

In my sample code below, in the "getPortName" prototype in the forEach loop, I declare a port object to store the serial port information before push into an array,

Is this a good way of declaring this port object?

  I think is not good because it is difficult for users to see what the objects members contain, is there anyway to make it clearly expose the port object member?

  Or there is 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;

JavaScript OOP structuring data class

I am trying to create a class for serial port using Node.js, but I want to know if there is a better way to write my data class code.

In my sample code below, in the getPortName prototype in the forEach loop, I declare a port object to store the serial port information before pushing 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 objects' members contain. Is there any way to make it clearly expose the port object member? Or 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;
added 62 characters in body
Source Link
Tim
  • 337
  • 1
  • 12

I am trying to create a class for serial port using Node.js,

But I want to know is there a better way to write my data class code?

In my sample code below, in the "getPortName" prototype in the forEach loop, I declare a port object to store the serial port information before push into an array,

Is this a good way of declaring this port object?

I think is not good because it is difficult for users to see what the objects members contain, is there anyway to make it clearly expose the port object member?

Or there is 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: 
     pnpId:  
   }

        ports.forEach(function(port) {}

            port.comName = port.comName;
            port.manufacturer = port.manufacturer;
            port.pnpId = port.pnpId;
        }    availablePorts.push(port);
        availablePorts.push(port});
    });

    return availablePortsavailablePorts;
};

Serial.prototype.setCOMName = function(name) {
    this.ComName = name;
}

module.exports = Serial;

I am trying to create a class for serial port using Node.js,

But I want to know is there a better way to write my data class code?

In my sample code below, in the "getPortName" prototype in the forEach loop, I declare a port object to store the serial port information before push into an array,

Is this a good way of declaring this port object?

I think is not good because it is difficult for users to see what the objects members contain, is there anyway to make it clearly expose the port object member?

Or there is 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 = [];
        var port = {
            comName: "",
            manufacturer: "",
            pnpId: 
         }

        ports.forEach(function(port) {
            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;

I am trying to create a class for serial port using Node.js,

But I want to know is there a better way to write my data class code?

In my sample code below, in the "getPortName" prototype in the forEach loop, I declare a port object to store the serial port information before push into an array,

Is this a good way of declaring this port object?

I think is not good because it is difficult for users to see what the objects members contain, is there anyway to make it clearly expose the port object member?

Or there is 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;
added 4 characters in body
Source Link
Alexis King
  • 3.2k
  • 2
  • 21
  • 35
Loading
added 62 characters in body
Source Link
Tim
  • 337
  • 1
  • 12
Loading
added 76 characters in body
Source Link
Alexis King
  • 3.2k
  • 2
  • 21
  • 35
Loading
Source Link
Tim
  • 337
  • 1
  • 12
Loading