考虑到这个JavaScript"类"定义,这是我能想到的最好的方法来解决这个问题:
var Quota = function(hours, minutes, seconds){
if (arguments.length === 3) {
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
this.totalMilliseconds = Math.floor((hours * 3600000)) + Math.floor((minutes * 60000)) + Math.floor((seconds * 1000));
}
else if (arguments.length === 1) {
this.totalMilliseconds = hours;
this.hours = Math.floor(this.totalMilliseconds / 3600000);
this.minutes = Math.floor((this.totalMilliseconds % 3600000) / 60000);
this.seconds = Math.floor(((this.totalMilliseconds % 3600000) % 60000) / 1000);
}
this.padL = function(val){
return (val.toString().length === 1) ? "0" + val : val;
}; …Run Code Online (Sandbox Code Playgroud) 有人可以使用下面的示例数据解释JavaScript Truthy和Falsy.我已阅读其他主题但仍感到困惑.
var a = 0;
var a = 10 == 5;
var a = 1;
var a = -1;
Run Code Online (Sandbox Code Playgroud)
根据我的理解,我相信这var a = 1;是唯一的真理,其余的都是假的 - 这是正确的吗?