简体   繁体   English

TypeScript类改为另一个类

[英]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! 而且我不知道如何构建AnotherClass()来存储此值,谢谢您的帮助!

You have to tell values what this refers to. 您必须告诉values this是什么意思。 I'm not sure what .fill does, but you could probably just use .call , and do it like this: 我不知道什么.fill ,但你很可能只是用.CALL ,并做到这一点是这样的:

 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} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM