Wednesday, January 9, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...