Commit 4d3ccafa authored by Kerem Çubuk's avatar Kerem Çubuk
Browse files

Update: syntax

parent f0613d6b
No related merge requests found
Showing with 19 additions and 19 deletions
+19 -19
......@@ -162,21 +162,21 @@ These components put together are termed as the data members of the class.
```javascript
class Person {
constructor(fname, lname, age) {
this._fname = fname;
this._lname = lname;
this._age = age;
this.firstName = fname;
this.lastName = lname;
this.pAge = age;
}
get name() {
return this._fname.toUpperCase();
return this.firstName.toUpperCase();
}
set name(fname) {
this._fname = fname;
this.firstName = fname;
}
get fullname() {
return this._fname + ' ' + this._lname;
return this.firstName + ' ' + this.lastName;
}
formatted() {
return 'Name is: ' + this._fname;
return 'Name is: ' + this.firstName;
}
}
......@@ -207,7 +207,7 @@ You do so by using the `${...}` syntax.
function templates() {
let people = [new Person('Murat', 'Karakas', 37), new Person('Faruk', 'Yazici', 28)];
for (let person of people) {
console.log(`Fullname: ${person.fullname}, Age: ${person._age}`);
console.log(`Fullname: ${person.fullname}, Age: ${person.pAge}`);
}
}
```
......@@ -269,7 +269,7 @@ function arrowFunctionExpression() {
// Arrow functions used inside an Array filter and map
function arrowFunctionMapFilter() {
let people = [new Person('Sedat', 'Öztürk', 24), new Person('Murat', 'Karakas', 37), new Person('Faruk', 'Yazici', 27)];
var fullnames = people.filter(p => p._age >= 25).map(p => p.fullname);
var fullnames = people.filter(p => p.pAge >= 25).map(p => p.fullname);
console.log(fullnames);
}
```
......
......@@ -46,21 +46,21 @@ function generatorConsume() {
class Person {
constructor(fname, lname, age) {
this._fname = fname;
this._lname = lname;
this._age = age;
this.firstName = fname;
this.lastName = lname;
this.pAge = age;
}
get name() {
return this._fname.toUpperCase();
return this.firstName.toUpperCase();
}
set name(fname) {
this._fname = fname;
this.firstName = fname;
}
get fullname() {
return this._fname + ' ' + this._lname;
return this.firstName + ' ' + this.lastName;
}
formatted() {
return 'Name is: ' + this._fname;
return 'Name is: ' + this.firstName;
}
}
......@@ -75,14 +75,14 @@ function classes() {
console.log(person.name)
console.log(person.fullname)
// Setter example
person._fname = 'Murat'
person.firstName = 'Murat'
console.log(person.name)
}
function templates() {
let people = [new Person('Murat', 'Karakas', 37), new Person('Faruk', 'Yazici', 28)];
for (let person of people) {
console.log(`Fullname: ${person.fullname}, Age: ${person._age}`);
console.log(`Fullname: ${person.fullname}, Age: ${person.pAge}`);
}
}
......@@ -98,7 +98,7 @@ function arrowFunctionMapFilter() {
console.log('---arrowFunctionMapFilter---')
let people = [new Person('Sedat', 'Öztürk', 24), new Person('Murat', 'Karakas', 37), new Person('Faruk', 'Yazici', 27)];
var fullnames = people.filter(p => p._age >= 25).map(p => p.fullname);
var fullnames = people.filter(p => p.pAge >= 25).map(p => p.fullname);
console.log(fullnames);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment