class Sample {
constructor(value) {
this.#internal = value
}
[Symbol.compareTo](b) { // returns `-1`, `0`, `1`
if (input instanceof Sample) {
return this.#internal < b.#internal ? 1 : -1
}
return -1
}
}
const samples = [
new Sample(2),
new Sample(1),
]
samples.sort() // effect `Array.prototyp.sort` default behavior
References: