What about having Symbol.equals?
For example, for now this is what it does:
```js
class Position {
    constructor(o) {
        this.x = o.x instanceof Number ? o.x : 0
        this.y = o.y instanceof Number ? o.y : 0
        this.z = o.z instanceof Number ? o.z : 0
    }
}
console.log(new Position({x: 10, y: 10, z: 10}) === new Position({x: 10, y: 10, 
z: 10})
```
Output is of course, false.
With `Symbol.equals`, we could make it easier, instead of 
`instance.equals(otherInstance)`.

For example:
```js
class Position {
    [Symbol.equals](oIn) {
        return oIn.x === this.x && oIn.y === this.y && oIn.z === this.z
    }
    constructor(o) {
        this.x = o.x instanceof Number ? o.x : 0
        this.y = o.y instanceof Number ? o.y : 0
        this.z = o.z instanceof Number ? o.z : 0
    }
}
console.log(new Position({x: 10, y: 10, z: 10}) === new Position({x: 10, y: 10, 
z: 10})
```
Now output would be true.
This would save most of the time, instead of writing .equals and then 
surrounding everything with ().


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to