Skip to content

Commit cb1c48d

Browse files
author
Konstantin Simeonov
committed
Split slides and added more slides
1 parent 9e96273 commit cb1c48d

3 files changed

Lines changed: 213 additions & 139 deletions

File tree

‎Topics/04. Classes-and-Class-Constructors/README.md‎

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -117,131 +117,6 @@ const gosho = new Superhero();
117117
```
118118

119119

120-
<!-- attr: { showInPresentation:true, hasScriptWrapper:true } -->
121-
# Methods
122-
- Classes can define methods with the same syntax as a constructor:
123-
124-
```js
125-
class Cat {
126-
constructor(name) {
127-
this._name = name;
128-
}
129-
130-
meow() {
131-
console.log(this.name + ': meow!');
132-
}
133-
}
134-
135-
const mariya = new Cat('Mariya');
136-
mariya.meow();
137-
```
138-
139-
<!-- attr: { showInPresentation:true, hasScriptWrapper:true, style:'font-size:0.9em' } -->
140-
# Getters and setters
141-
- Classes also provide **getter** and **setter** syntax
142-
- Getters and setters are used like data fields, but are actually methods
143-
- Can be used to encapsulate data and control access to it
144-
- Getters to get values of private properties
145-
- Setter to change values of private properties
146-
147-
<!-- attr: { showInPresentation:true, hasScriptWrapper:true, style:'font-size:0.8em' } -->
148-
# Getters and setters
149-
150-
```js
151-
class Person {
152-
constructor(firstname, lastname) {
153-
this._firstname = firstname;
154-
this._lastname = lastname;
155-
}
156-
157-
get fullname() {
158-
return this._firstname + ' ' + this._lastname;
159-
}
160-
161-
set firstname(value) {
162-
this._firstname = value;
163-
}
164-
165-
set lastname(value) {
166-
this._lastname = value;
167-
}
168-
}
169-
170-
const peter = new Person('peter', 'anderson');
171-
console.log(peter.fullname);
172-
peter.lastname = 'petrov';
173-
console.log(peter.fullname);
174-
```
175-
176-
<!-- section start -->
177-
<!-- attr: { showInPresentation:true, hasScriptWrapper:true } -->
178-
# Classes and Inheritance in ES6
179-
- ES6 introduces classes and a way to create classical OOP
180-
181-
```javascript
182-
class Person extends Mammal {
183-
constructor(fname, lname, age) {
184-
super(age);
185-
this._fname = fname;
186-
this._lname = lname;
187-
}
188-
get fullname() {
189-
//getter property of fullname
190-
}
191-
set fullname(newfullname) {
192-
//setter property of fullname
193-
}
194-
// more class members…
195-
}
196-
```
197-
198-
<!-- attr: { showInPresentation:true, hasScriptWrapper:true } -->
199-
# Classes and Inheritance in ES6
200-
- ES6 introduces classes and a way to create classical OOP
201-
202-
```javascript
203-
class Person extends Mammal {
204-
constructor(fname, lname, age) {
205-
super(age);
206-
this._fname = fname;
207-
this._lname = lname;
208-
}
209-
get fullname() {
210-
//getter property of fullname
211-
}
212-
set fullname(newfullname) {
213-
//setter property of fullname
214-
}
215-
// more class members…
216-
}
217-
```
218-
219-
<div class="fragment balloon" style="top:35.42%; left:54.30%; width:41.45%">Constructor of the class</div>
220-
221-
<!-- attr: { showInPresentation:true, hasScriptWrapper:true } -->
222-
# Classes and Inheritance in ES6
223-
- ES6 introduces classes and a way to create classical OOP
224-
225-
```javascript
226-
class Person extends Mammal {
227-
constructor(fname, lname, age) {
228-
super(age);
229-
this._fname = fname;
230-
this._lname = lname;
231-
}
232-
get fullname() {
233-
//getter property of fullname
234-
}
235-
set fullname(newfullname) {
236-
//setter property of fullname
237-
}
238-
// more class members…
239-
}
240-
```
241-
242-
<div class="fragment balloon" style="top:56.84%; left:55.19%; width:41.45%">Getters and setters</div>
243-
<div class="fragment balloon" style="top:35.42%; left:54.30%; width:41.45%">Constructor of the class</div>
244-
245120
<!-- Questions -->
246121
<!-- section start -->
247122
<!-- attr: { hasScriptWrapper:true, showInPresentation:true, class:"slide-questions", id:"questions" } -->
Lines changed: 145 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,162 @@
11
<!-- section start -->
2-
<!-- attr: { id:'', class:'slide-title', showInPresentation:true, hasScriptWrapper:true } -->
3-
# Class Methods and Properties
4-
##
2+
<!-- attr: { class:'slide-title', hasScriptWrapper:true } -->
3+
# Class methods and Properties
4+
55
<article class="signature">
66
<p class="signature-course">JavaScript OOP</p>
77
<p class="signature-initiative">Telerik Software Academy</p>
8-
<a href="http://academy.telerik.com " class="signature-link">http://academy.telerik.com </a>
9-
</div>
8+
<a href="http://academy.telerik.com" class="signature-link">http://academy.telerik.com</a>
9+
</article>
10+
11+
12+
<!-- section start -->
13+
<!-- attr: { showInPresentation:true, hasScriptWrapper:true } -->
14+
# Table of Contents
15+
- Class methods
16+
- Properties
17+
- Getters and Setters
18+
- JavaScript Prototypes
19+
20+
<!-- section start -->
21+
<!-- attr: { showInPresentation: true, class: 'slide-section' } -->
22+
# Class Methods
23+
## Attach functionality to class instances
24+
25+
<!-- attr: { showInPresentation:true, hasScriptWrapper:true } -->
26+
# Class Methods
27+
- Methods are functions in the context of a class
28+
- Classes can define methods with the same syntax as a constructor:
29+
30+
```js
31+
class Cat {
32+
constructor(name) {
33+
this._name = name;
34+
}
35+
36+
meow() {
37+
console.log(this.name + ': meow!');
38+
}
39+
}
40+
41+
const mariya = new Cat('Mariya');
42+
mariya.meow(); // mariya: meow!
43+
```
44+
45+
<!-- attr: { showInPresentation:true, hasScriptWrapper:true, style: 'font-size: 0.9em' } -->
46+
# Class Methods
47+
- When a method is called, the following happens
48+
- The context of the function is set to the object which it's called from
49+
- `this` is a reference to the object the method is called from
50+
51+
```js
52+
class SelfPrintingCat {
53+
constructor(name) {
54+
this._name = name;
55+
}
56+
57+
printSelf() {
58+
console.log(this);
59+
}
60+
}
61+
const fluff = new SelfPrintingCat('Fluff');
62+
fluff.printSelf(); // { _name: 'Fluff' }
63+
```
64+
65+
<!-- section start -->
66+
<!-- attr: { showInPresentation: true, class: 'slide-section' } -->
67+
# Getters and setters
68+
## Control access to fields
1069

70+
<!-- attr: { showInPresentation:true, hasScriptWrapper:true, style:'font-size:0.9em' } -->
71+
# Getters and setters
72+
- Classes also provide **getter** and **setter** syntax
73+
- Getters and setters are used like data fields, but actually behave like methods
74+
- Can be used to encapsulate data and control access to it
75+
- Getters to get values of fields
76+
- Setter to change values of fields
77+
78+
<!-- attr: { showInPresentation:true, hasScriptWrapper:true, style:'font-size:0.8em' } -->
79+
# Getters and setters
80+
81+
```js
82+
class Person {
83+
constructor(firstname, lastname) {
84+
this._firstname = firstname;
85+
this._lastname = lastname;
86+
}
87+
88+
get fullname() {
89+
return this._firstname + ' ' + this._lastname;
90+
}
91+
92+
set firstname(value) {
93+
this._firstname = value;
94+
}
95+
96+
set lastname(value) {
97+
this._lastname = value;
98+
}
99+
}
100+
101+
const peter = new Person('peter', 'anderson');
102+
console.log(peter.fullname);
103+
peter.lastname = 'petrov';
104+
console.log(peter.fullname);
105+
```
106+
107+
<!-- section start -->
108+
<!-- attr: { showInPresentation: true, class: 'slide-section' } -->
109+
# JavaScript Prototypes
110+
## The true nature of JavaScript
111+
112+
<!-- attr: { showInPresentation:true, hasScriptWrapper:true, style:'font-size:0.9em' } -->
113+
# Prototypes
114+
- Class methods, getters and setters aren't directly attached to the objects
115+
- They're attached to their `prototypes`
116+
- In JavaScript, objects inherit from other objects
117+
- Consider the `SelfPrintingCat` example:
118+
119+
```js
120+
new SelfPrintingCat('Fluff').printSelf(); // { _name: 'Fluff' }
121+
```
122+
- The `printSelf` method is not attached to `fluff`
123+
124+
<!-- attr: { showInPresentation:true, hasScriptWrapper:true } -->
125+
# Prototypes
126+
- To access the prototype of `fluff`, when can write the following:
127+
128+
```js
129+
const catProto = SelfPrintingCat.prototype;
130+
console.log(typeof catProto.printSelf); // function
131+
```
132+
133+
<!-- attr: { showInPresentation:true, hasScriptWrapper:true, style:'font-size:0.9em' } -->
134+
# Prototypes
135+
- JavaScript prototypes allow us to extend a class dynamically
136+
- We can make the `SelfPrintingCat` meow
137+
138+
```js
139+
SelfPrintingCat.prototype.meow = function () {
140+
console.log(this._name + ': meow'!);
141+
};
142+
```
11143

12144

13145
<!-- Questions -->
14146
<!-- section start -->
15-
<!-- attr: { hasScriptWrapper:true, class:"slide-questions", id:"questions" } -->
16-
<!-- # Class Methods and Properties
147+
<!-- attr: { hasScriptWrapper:true, showInPresentation:true, class:"slide-questions", id:"questions" } -->
148+
<!-- # ES6 Classes and Class Constructors
17149
## Questions? -->
18150

19-
20-
<!-- attr: { showInPresentation: true, hasScriptWrapper: true, style:'font-size: 0.9em' } -->
21-
# Free Trainings<br/>@ Telerik Academy
151+
<!-- attr: { showInPresentation:true, hasScriptWrapper:true, style:'font-size: 0.9em' } -->
152+
# Free Trainings @ Telerik Academy
22153
- "Web Design with HTML 5, CSS 3 and JavaScript" course @ Telerik Academy
23154
- [javascript course](http://academy.telerik.com/student-courses/web-design-and-ui/javascript-fundamentals/about)
24155
- Telerik Software Academy
25-
- [academy.telerik.com](academy.telerik.com)
156+
- [academy.telerik.com](http://academy.telerik.com)
26157
- Telerik Academy @ Facebook
27-
- [facebook.com/TelerikAcademy](facebook.com/TelerikAcademy)
158+
- [facebook.com/TelerikAcademy](https://facebook.com/TelerikAcademy)
28159
- Telerik Software Academy Forums
29-
- [forums.academy.telerik.com](http://telerikacademy.com/Forum/Home)
160+
- [forums.academy.telerik.com](https://telerikacademy.com/Forum/Home)
30161

31-
<!-- <img class="slide-image" showInPresentation="true" src="imgs/pic00.png" style="top:58.18%; left:90.52%; width:16.97%; z-index:-1" /> -->
162+
<!-- <img class="slide-image" showInPresentation="false" src="imgs/pic00.png" style="top:58.18%; left:90.52%; width:16.97%; z-index:-1" /> -->

‎Topics/06. Class-Inheritance/README.md‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,74 @@
88
<a href="http://academy.telerik.com " class="signature-link">http://academy.telerik.com </a>
99
</div>
1010

11+
<!--
12+
# Classes and Inheritance in ES6
13+
- ES6 introduces classes and a way to create classical OOP
14+
15+
```javascript
16+
class Person extends Mammal {
17+
constructor(fname, lname, age) {
18+
super(age);
19+
this._fname = fname;
20+
this._lname = lname;
21+
}
22+
get fullname() {
23+
//getter property of fullname
24+
}
25+
set fullname(newfullname) {
26+
//setter property of fullname
27+
}
28+
// more class members…
29+
}
30+
```
31+
32+
33+
# Classes and Inheritance in ES6
34+
- ES6 introduces classes and a way to create classical OOP
35+
36+
```javascript
37+
class Person extends Mammal {
38+
constructor(fname, lname, age) {
39+
super(age);
40+
this._fname = fname;
41+
this._lname = lname;
42+
}
43+
get fullname() {
44+
//getter property of fullname
45+
}
46+
set fullname(newfullname) {
47+
//setter property of fullname
48+
}
49+
// more class members…
50+
}
51+
```
52+
53+
<div class="fragment balloon" style="top:35.42%; left:54.30%; width:41.45%">Constructor of the class</div>
54+
55+
56+
# Classes and Inheritance in ES6
57+
- ES6 introduces classes and a way to create classical OOP
58+
59+
```javascript
60+
class Person extends Mammal {
61+
constructor(fname, lname, age) {
62+
super(age);
63+
this._fname = fname;
64+
this._lname = lname;
65+
}
66+
get fullname() {
67+
//getter property of fullname
68+
}
69+
set fullname(newfullname) {
70+
//setter property of fullname
71+
}
72+
// more class members…
73+
}
74+
```
75+
76+
<div class="fragment balloon" style="top:56.84%; left:55.19%; width:41.45%">Getters and setters</div>
77+
<div class="fragment balloon" style="top:35.42%; left:54.30%; width:41.45%">Constructor of the class</div> -->
78+
1179
<!-- Questions -->
1280
<!-- section start -->
1381
<!-- attr: { hasScriptWrapper:true, class:"slide-questions", id:"questions" } -->

0 commit comments

Comments
 (0)