Recently, I've been working on a ShadowCljs project where I needed to extend a JavaScript class in Clojurescript, create an object, and pass it back to a JavaScript method. After researching various options, I found that the simplicity aspect was lacking. I decided to create a solution that addresses this issue.

Consider your npm package ***testcljs*** has a class

export class Vehicle{
    constructor(public name: string, public speed: number){}

    public getDetails(): string{
        return `Vehicle: ${this.name} with speed ${this.speed}`;
    }
}

export function drive(vehicle: Vehicle): string{
    return `Driving ${vehicle.getDetails()}`;
}

Need to create a version of the Vehicle class that has a different implementation for the getDetails() method, while still being able to use the drive() function

Also new version of the method will call the super.getDetails() method to get the details from the parent class and add additional information before returning the final string

The typical Javascript which we need to implement in CLJS is something like this

export class ExtendedVehicle extends Vehicle{
    constructor(public name: string, public speed: number){

        super(name,speed);
    }

    public getDetails(): string{
        return `Vehicle: ${super.getDetails()} and with extended capabilities`;
    }
}

Lets see , How to create it , without much verbose and utilizing clojure’s simplicity

In Cljs import the class and method