如果我想将一个类型分配给一个变量,稍后将为其分配一个setInterval,如下所示:
this.autoSaveInterval = setInterval(function(){
if(this.car.id){
this.save();
}
else{
this.create();
}
}.bind(this), 50000);
应该为this.autosave Interval变量分配什么类型?
类型是数字;
private autoSaveInterval: number = setInterval( ()=>{console.log('123')},5000);
使用typeof运算符查找任何变量的数据类型,如下所示:
typeof是一个一元运算符,放在一个可以是任何类型的操作数之前。它的值是一个字符串,它指定操作数的类型。
var variable1 = "Hello";
var autoSaveInterval;
this.autoSaveInterval = setInterval(function(){
if(this.car.id){
this.save();
}
else{
this.create();
}
}.bind(this), 50000);
console.log("1st: " + typeof(variable1))
console.log("2nd: " + typeof(autoSaveInterval ))