From dd106baf4cd52e4197c186ffd5b84867d5850853 Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Sun, 19 May 2019 19:37:27 +0300 Subject: [PATCH] class --- 1-js/09-classes/01-class/article.md | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/1-js/09-classes/01-class/article.md b/1-js/09-classes/01-class/article.md index 7c164ca1..0c10960c 100644 --- a/1-js/09-classes/01-class/article.md +++ b/1-js/09-classes/01-class/article.md @@ -232,7 +232,7 @@ new User().sayHi(); // Hello ## Getters/setters, other shorthands -Classes also include getters/setters, generators, computed properties etc. +Just like literal objects, classes may include getters/setters, generators, computed properties etc. Here's an example for `user.name` implemented using `get/set`: @@ -325,24 +325,6 @@ The property is not placed into `User.prototype`. Instead, it is created by `new ## Summary -JavaScript provides many ways to create a class. - -First, as per the general object-oriented terminology, a class is something that provides "object templates", allows to create same-structured objects. - -When we say "a class", that doesn't necessary means the `class` keyword. - -This is a class: - -```js -function User(name) { - this.sayHi = function() { - alert(name); - } -} -``` - -...But in most cases `class` keyword is used, as it provides great syntax and many additional features. - The basic class syntax looks like this: ```js @@ -363,6 +345,6 @@ class MyClass { } ``` -`MyClass` is technically a function, while methods are written to `MyClass.prototype`. +`MyClass` is technically a function (the one that we provide as `constructor`), while methods, getters and settors are written to `MyClass.prototype`. In the next chapters we'll learn more about classes, including inheritance and other features.