Показать сообщение отдельно
  #4 (permalink)  
Старый 19.06.2019, 16:51
Аватар для Malleys
Профессор
Отправить личное сообщение для Malleys Посмотреть профиль Найти все сообщения от Malleys
 
Регистрация: 20.12.2009
Сообщений: 1,714

constructor так и так остаётся... Вот для примера код...

<script>
class Person {
	constructor(name, age) {
		this.name = name;
		this.age = age;
	}

	say(message) {
		return this.name + " says: '" + message + "'";
	}
}

class Cat extends Person {
	constructor(name, age, breed) {
		super("Cat " + name, age);
		this.breed = breed;
	}

	say(message) {
		return super.say("Meow! " + message);
	}
}

const cat = new Cat("Vector", 4, "Maine Coon");
alert(cat.say("Hello!"));
</script>


Вот этот же самый пример без специального синтаксиса классов... Согласитесь, специальный синтаксис упрощает написание кода...
<script>
function Person(name, age) {
	this.name = name;
	this.age = age;
}

Person.prototype = {
	constructor: Person,

	say(message) {
		return this.name + " says: '" + message + "'";
	}
};

function Cat(name, age, breed) {
	this.__proto__.__proto__.constructor.call(this, "Cat " + name, age);
	this.breed = breed;
}

Cat.prototype = {
	__proto__: Person.prototype,
	
	constructor: Cat,

	say(message) {
		return this.__proto__.__proto__.say.call(this, "Meow! " + message);
	}
};

const cat = new Cat("Vector", 4, "Maine Coon");
alert(cat.say("Hello!"));
</script>


А код, который вы показали он не является стандартным... там, как я и предвидел используется JSX... Вы можете перевести метод render в ES2019...
render() {
		return React.createElement(
			"div",
			{ className: "container" },
			React.createElement("h1", null, "E-commerce Shopping Cart Application"),
			React.createElement("hr", null),
			React.createElement(
				"div",
				{ className: "row" },
				React.createElement(
					"div",
					{ className: "col-md-9" },
					React.createElement(Filter, {
						count: this.state.filteredProducts.length,
						handleSortChange: this.handleSortChange,
						handleSizeChange: this.handleSizeChange
					}),
					React.createElement("hr", null),
					React.createElement(Products, {
						products: this.state.filteredProducts,
						handleAddToCart: this.handleAddToCart
					})
				),

				React.createElement(
					"div",
					{ className: "col-md-3" },
					React.createElement(Basket, {
						cartItems: this.state.cartItems,
						handleRemoveFromCart: this.handleRemoveFromCart
					})
				)
			)
		);
	}

Последний раз редактировалось Malleys, 19.06.2019 в 16:54.
Ответить с цитированием