이 ES6 클래스를 만들었고 생성자에서 정의한 변수를 사용하려고하는데 console.log가 this.customerTz
인 경우 undefined
을 반환합니다.Es6 클래스 변수
나는 변수를 클래스의 맨 위에 놓으려고했으나 작동하지 않는 것 같습니다.
변수를 사용할 수 있습니까? convertToUtc
이후
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;
}
}