Dynamcally creating instances of a class using a function in javascript

The title is really long, and was sort of hard to search for, so thought I’d ask for help here :slight_smile:
I’m completely new to programming, so there’s probably something really basic I’m missing:

How do I create an instance of a class with a function and give it a new name each time? For instance just a serial number. Let’s say I want to create a new instance each time a user clicks a button.

Haven’t gotten very far before this problem cropped up, so don’t really have a code example…

Any help appreciated :slight_smile:

class SerialNumber {
    constructor(vin) {
        this.vin = vin
let honda = new SerialNumber('HKM123456LX')

console.log(honda.vin)    // HKM123456LX

That’s just a sketch of a VIN class. New instances can be invoked from anywhere in the program.

Please show us what you have for code, so far, and describe what it is you are attempting to do.


I’ll try to make something somewhat understandable, and get back to you :slight_smile:

1 Like