Skip to content

Instantly share code, notes, and snippets.

@hmel1990
Created May 16, 2025 13:35
Show Gist options
  • Save hmel1990/d3fe1ae34206f605caebd9e1556cd08e to your computer and use it in GitHub Desktop.
Save hmel1990/d3fe1ae34206f605caebd9e1556cd08e to your computer and use it in GitHub Desktop.
ClassExtends
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Classes</title>
</head>
<body>
<p>
Задание 1
Реализовать класс Button, который содержит ширину, высоту, текст кнопки и метод showBtn(),<br>
который выводит кнопку на экран с помощью тега button и функции document.write().<br>
Реализовать класс BootstrapButton, унаследовав его от класса Button.<br>
Добавить поле color и переопределить метод showBtn() так,<br>
чтобы кнопка выводилась со стилями и указанным цветом.<br>
</p>
<script>
class Button
{
width;
height;
buttonText;
constructor(width = 150, height = 20, buttonText = "buttonText")
{
this.width = width;
this.height = height;
this.buttonText = buttonText;
}
showBtn()
{
document.write(`<button style="
width: ${this.width}px;
height: ${this.height}px;">
${this.buttonText}</button>`);
}
}
class BootstrapButton extends Button
{
constructor(width = 150, height = 20, buttonText = "buttonText", color = "red")
{
super(width, height, buttonText);
this.color = color;
}
showBtn()
{
document.write(`<button style="
width: ${this.width}px;
height: ${this.height}px;
color: ${this.color}">
${this.buttonText}</button>`);
}
}
const btn = new Button(150,25,"buttonText111");
btn.showBtn();
const btstbtn = new BootstrapButton();
btstbtn.showBtn();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment