mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 20:01:31 +00:00
Init classes samples
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Javascript Training</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Javascript Training</h1>
|
||||
<script src="./index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,31 @@
|
||||
class Person {
|
||||
name;
|
||||
age(year) {
|
||||
return 2023 - year;
|
||||
}
|
||||
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
printMessage() {
|
||||
console.log(`Hello, I'm ${this.name}`);
|
||||
}
|
||||
|
||||
static printAge() {
|
||||
console.log("I'm 22 years old!");
|
||||
}
|
||||
}
|
||||
|
||||
const nezumiUser = new Person();
|
||||
|
||||
nezumiUser.name = "Example name";
|
||||
|
||||
console.log(nezumiUser["name"]);
|
||||
console.log(nezumiUser.name);
|
||||
console.log(nezumiUser.age(2001));
|
||||
|
||||
const anotherUser = new Person("Nezumi");
|
||||
anotherUser.printMessage();
|
||||
|
||||
Person.printAge();
|
||||
Reference in New Issue
Block a user