<commit_before>---
layout: post
title:  "Javascript Prototypes and Object Oriented Programming."
date:   2017-04-03 20:35:24 -0400
---

After C++, Java and Ruby, Javascript seems for me a little bit hard to understand. It is different in its core. It is prototype-based object oriented language. In this article I would like to write about it.

In class-based object orientation we must first design the Class, blueprint of an object. And only then we can create objects which will have the same properties as this Class. The Class is a **nonfunctional** structure. On the contrary, the prototype-based object orientation means that we create objects from the other existing, **functional** objects. The difference between these two approaches becomes especially obvious when we talk about inheritance.

First of all, in JS all data are objects. Namely, functions in JS are first class functions (unlike Ruby). They can serve as variables and can be passed as arguments to other functions. So actually they are objects with their own properties and methods. Functions can serve as constructors for new objects:

```
function Dog(name) { this.name = name }
let fido = new Dog(“Fido”)
```

In this example I created `fido` from the `Dog` constructor. As you can see, JS doesn’t use classes as blueprints. It uses real functional functions (if you can say so :) ) to create new objects.
<commit_msg>Updating my blog post.<commit_after>---
layout: post
title:  "Javascript Prototypes and Object Oriented Programming"
date:   2017-04-03 20:35:24 -0400
---

After C++, Java and Ruby, Javascript seems for me a little bit hard to understand. It is different in its core. It is prototype-based object oriented language. In this article I would like to write about it.

In class-based object orientation we must first design the Class, blueprint of an object. And only then we can create objects which will have the same properties as this Class. The Class is a **nonfunctional** structure. On the contrary, the prototype-based object orientation means that we create objects from the other existing, **functional** objects. The difference between these two approaches becomes especially obvious when we talk about inheritance.

First of all, in JS all data are objects. Namely, functions in JS are first class functions (unlike Ruby). They can serve as variables and can be passed as arguments to other functions. So actually they are objects with their own properties and methods. Functions can serve as constructors for new objects:

```
function Dog(name) { this.name = name }
let fido = new Dog(“Fido”)
```

In this example I created `fido` from the `Dog` constructor. As you can see, JS doesn’t use classes as blueprints. It uses real functional functions (if you can say so :) ) to create new objects.

{'fraction_non_alphanumeric': 0.06142857142857143, 'fraction_numerical': 0.012857142857142857, 'mean_word_length': 4.345419847328245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3439783', 'n_tokens_mistral': 713, 'n_tokens_neox': 660, 'n_words': 429}