class Time{
constructor(hours,minutes){
this.hours=hours;
this.minutes=minutes;
}
addTime(val=0,func=showTime){ //How can I write this part too?<--
this.minutes+=val;
if(this.minutes>60){
this.hour++;
this.minutes-=60;
}
return this.func() //this was something I was toying with<--
}
round(){
switch(this.minutes%5){
case 0:break;
case 1:this.minutes-=1;break;
case 2:this.minutes-=2;break;
case 3:this.minutes+=2;break;
case 4:this.minutes+=1;break;
default:break;
}
//console.log(this.minutes)
return this.hours+":"+this.minutes; //here too... I didn't know how to return a method<--
}
showTime(){
return this.hours+":"+this.minutes;
}
}
如果你想在另一个函数中访问同一个类的函数,我建议使用self
参数。前任。def function_name(self, other_parameters)
. 这里 'self' 表示类,然后您可以使用self.function_name
.
因此,在您的程序中,您可以使用以下代码调用另一个函数中的其他函数:
def func1(self):
#code
def func2(self):
self.func1
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句