我做了这个ES6类,我试图使用我在构造函数中定义的变量,但是当我console.log this.customerTz
它返回undefined
。Es6类变量
我也试着把变量放在类的顶部,但它似乎不工作。
是否有可能有变量?
class DateTimeConverter {
constructor() {
this.format = 'YYYY-MM-DD HH:mm:ss';
this.customerTz = 'Europe/Oslo';
}
static convertToUtc(date) {
console.log(this.customerTz);
// Set customer timezone
date = moment.tz(date, this.customerTz);
// Convert to UTC
date = date.clone().tz('UTC');
// Set format to something PHP thinks is valid
date = date.format(this.format);
return date;
}
}