@adrenalinruslan

Как мне получить значение переменной?

Как мне получить значение 300 переменной width, делал вот так, выходит undefined:

let testing = {
			width: undefined,
			zero: undefined,

			init: function() {
				this.width = 300;
			},

			start: function() {
				this.init();

				console.log(this.zero.x);
			},
		};

		testing.zero = {
			x: testing.width,
		};

		window.onload = () => {
			testing.start();
		};


Пробовал вот так, все заработало, но можно как то по другому ?

let testing = {
			width: undefined,
			zero: undefined,

			init: function() {
				this.width = 300;
			},

			start: function() {
				this.init();
				this.zero.start();

				console.log(this.zero.x);
			},
		};

		testing.zero = {
			x: undefined,

			start: function() {
				this.x = testing.width;
			},
		};

		window.onload = () => {
			testing.start();
		};
  • Вопрос задан
  • 86 просмотров
Пригласить эксперта
Ответы на вопрос 1
xEpozZ
@xEpozZ
Веб-разработчик
window.onload = () => {
    testing.start();
    testing.zero.start();
};
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы