On the Internet I found 2 approaches in programming, help me figure out how they are properly named, and in what case which one is better to use.

Links to literate manuals are welcome :)

Approach # 1:

var myVar = function() { return { myFunc: function() { ... } }; }(); myVar.myFunc() 

Approach # 2:

 function myClass(){ this.myProperty = 1; this.myFunction = function(){ ... } }; myVar = new myClass(); myVar.myProperty = 1; myVar.myFunction(); 
  • there is another one that uses prototypes - Umer
  • one
    @Umer, the second is just a special case - Grundy
  • @Grundy, in the sense of a special case of the prototype approach? - Umer
  • one
    @Alexander, and where you found them there was no description? - Grundy
  • one
    The answer will pull on a couple of hours of work) see it-ebooks.info/book/724 there is a link to the jump there. Or in Kratz scotch.io/bar-talk/4-javascript-design-patterns-you-should-know - Den

1 answer 1

This is not an approach to programming. These are 2 types of creation of objects in JS, from 4 a minimum.

https://habrahabr.ru/company/nixsolutions/blog/302518/
http://largescalejs.ru/
https://www.sitepoint.com/javascript-object-creation-patterns-best-practises/