The difference between {} and function () {} for classes

In Javascript, I can create a β€œclass” like this:

var MyClass = function(){ return this; }; var myClassInstance = new MyClass(); 

What is the difference between doing the above and doing this:

 var MyClass = {}; var myClassInstance = Object.create(MyClass); 

Is there any reason to use one over the other?

+6
source share

Source: https://habr.com/ru/post/976988/


All Articles