Wednesday 9 January 2019

javascript - how typescript comparing two objects?

I have one class called tax.



    export class tax {
private _id: string;
private _name: string;
private _percentage: number;`

constructor(id: string = "", taxName: string = "", percentage: number = 0) {
this._id = id;

this._name = taxName;
this._percentage = percentage;
}


public get id(): string {
return this._id;
}

public set id(v: string) {

this._id = v;
}
public get name(): string {
return this._name;
}

public set name(v: string) {
this._name = v;
}
public get percentage(): number {

return this._percentage;
}

public set percentage(v: number) {
this._percentage = v;
}

toString(){
return this.id;
}

}


When I create 2 different objects of this class



    a1: tax = new tax("id","name",4);
a2: tax = new tax("id","name",4);

console.log(a1 === a2); //false
console.log(a1 == a2); //false



When I give a1 === a2 it should give true.
what changes i have to do in my class so it will give a1 === a2 ?
What I have to do in tax class? or which method I have to override in tax class?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...