Pál Farkas
Pál Farkas

Reputation: 9

TypeScript class to another class

I have class values and I want to store it another class.

function values(data1,data2){
   this.one = data1;
   this.sec = data2;
}

I want store in another class this class values like ->

let ad = AnotherClass();
ad.fill(values(1,2));
ad.fill(values(5,2));

And I don't know how to build this AnotherClass() to store this values, thanks for the help!

Upvotes: 0

Views: 53

Answers (1)

dave
dave

Reputation: 64657

You have to tell values what this refers to. I'm not sure what .fill does, but you could probably just use .call, and do it like this:

var ad = {}

function values(data1,data2){
    this.one = data1;
    this.sec = data2;
}

 values.call(ad, 1, 2);
 values.call(ad, 5, 2)

 console.log(ad); // {one: 5, sec: 2}

Upvotes: 1

Related Questions