-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototypes.html
More file actions
39 lines (29 loc) · 764 Bytes
/
prototypes.html
File metadata and controls
39 lines (29 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html>
<head>
<title>Prototypes</title>
</head>
<body>
<script type="text/javascript">
//dodawanie metody do isntniejacego obiektu: nalezy dodac metode do prototype obiektu
//w tym przypadku dodajemy funckje lastYear do prototype obiektu Date
Date.prototype.lastYear = function () {return this.getFullYear() - 1}
console.log(new Date().lastYear());
//Person ma .prototype
var Person = function(name, age) {
this.name = name;
this.age = age;
}
var p1 = new Person("Monia", 24)
let arr = [1,2,3];
Array.prototype.map = function () {
let newArr = [];
this.forEach(function(element, index){
newArr.push(element + ' mapa');
});
return newArr;
}
console.log(arr.map());
</script>
</body>
</html>