我用打字稿创建了一个类。 当我试图将其转换为js并使用命令提示符运行时,我没有得到所需的输出。 这是我的课
class myclass{
j: number;
constructor(k: number){
this.j = k;
}
value (){
return("the number is "+this.j)
}
}
let myobj = new myclass(10)
console.log(myobj.value) .
你能建议什么是不起作用的。?
MyObj.value
是一个函数。
要打印实际值,必须使用MyObj.value()
调用函数
您可以使用typeof
关键字来发现错误,该关键字告诉您变量的类型。
null
class myclass {
j;
constructor(k) {
this.j = k;
}
value() {
return `the number is ${this.j}`;
}
}
const myobj = new myclass(10);
console.log(typeof myobj.value);