fix some minor mistakes

pull/113/head
Kamrul Islam Shahin 5 years ago
parent 7985dc1b9d
commit 464c9a9a04

@ -66,13 +66,13 @@ class Person {
} }
``` ```
We have created an Person class but it does not have any thing inside. We have created a Person class but it does not have anything inside.
### Class Instantiation ### Class Instantiation
Instantiation class means creating an object from a class. We need the keyword _new_ and we call the name of the class after the word new. Instantiation class means creating an object from a class. We need the keyword _new_ and we call the name of the class after the word new.
Let us create a dog object from our Person class. Let us create a person object from our Person class.
```js ```js
class Person { class Person {
@ -92,7 +92,7 @@ Let use the class constructor to pass different properties for the class.
### Class Constructor ### Class Constructor
The constructor is a builtin function which allows as to create a blueprint for our object. The constructor function starts with a keyword constructor followed by a parenthesis. Inside the parenthesis we pass the properties of the object as parameter. We use the _this_ keyword to attach the constructor parameters with the class. The constructor is a builtin function which allows us to create a blueprint for our object. The constructor function starts with a keyword constructor followed by a parenthesis. Inside the parenthesis we pass the properties of the object as parameter. We use the _this_ keyword to attach the constructor parameters with the class.
The following Person class constructor has firstName and lastName property. These properties are attached to the Person class using _this_ keyword. _This_ refers to the class itself. The following Person class constructor has firstName and lastName property. These properties are attached to the Person class using _this_ keyword. _This_ refers to the class itself.
@ -111,7 +111,7 @@ console.log(person)
``` ```
```sh ```sh
Person {firstName: undefined, lastName} Person {firstName: undefined, lastName: undefined}
``` ```
All the keys of the object are undefined. When ever we instantiate we should pass the value of the properties. Let us pass value at this time when we instantiate the class. All the keys of the object are undefined. When ever we instantiate we should pass the value of the properties. Let us pass value at this time when we instantiate the class.
@ -243,12 +243,12 @@ console.log(person2.getFullName())
```sh ```sh
Asabeneh Yetayeh Asabeneh Yetayeh
test.js:19 Lidiya Tekle Lidiya Tekle
``` ```
### Properties with initial value ### Properties with initial value
When we create a class for some properties we may have an initial value. For instance if you are playing a game, you starting score will be zero. So, we may have a starting score or score which is zero. In other way, we may have an initial skill and we will acquire some skill after some time. When we create a class for some properties we may have an initial value. For instance if you are playing a game, your starting score will be zero. So, we may have a starting score or score which is zero. In other way, we may have an initial skill and we will acquire some skill after some time.
```js ```js
class Person { class Person {
@ -551,11 +551,11 @@ The static methods are methods which can be used as utility functions.
## Inheritance ## Inheritance
Using inheritance we can access all the properties and the methods of the parent class. This reduces repetition of code. If you remember, we have a Person parent class and we will create children from it. Our children class could be student, teach etc. Using inheritance we can access all the properties and the methods of the parent class. This reduces repetition of code. If you remember, we have a Person parent class and we will create children from it. Our children class could be student, teacher etc.
```js ```js
// syntax // syntax
class ChildClassName extends { class ChildClassName extends ParentClassName {
// code goes here // code goes here
} }
``` ```

Loading…
Cancel
Save