Skip to content

Commit b810da8

Browse files
committed
feat: add tutorial about prototype
1 parent a711425 commit b810da8

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<script src="src/prototype.js"></script>
10+
</body>
11+
</html>

src/prototype.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This is simple way to create object.
2+
let firstObject = {
3+
propOne: "Property One",
4+
propTwo: 1,
5+
funcOne: function() {
6+
console.log("This is function of firstObject.");
7+
}
8+
}
9+
10+
// This is second way to create object.
11+
let secondObject = new Object({
12+
propOne: "Property Two",
13+
propTwo: 2,
14+
funcOne: function() {
15+
console.log("This is function of secondObject.");
16+
}
17+
});
18+
19+
// This is someFunc in Object prototype.
20+
Object.prototype.someFunc = function() {
21+
console.log("This is function of prototype.");
22+
}
23+
24+
// This is new object with prototype by firstObject.
25+
let cloneObject = Object.create(firstObject);
26+
27+
// This is new string.
28+
let someString = new String("Some text");

0 commit comments

Comments
 (0)