Please explain this construction on js (i.e., why you need it, when it is better to use, how to address its elements), as well as the meaning of the if-check (below):

if (!window.Upload) { var Upload = { init: function(obj, vars, options) { //... }, deinit: function(iUpload) { //... } }; } 

UPD 1:

Also interested in the type of Upload 'a.

  • How can one understand the meaning of a construction if there is nothing in it, dots? - hindmost
  • @hindmost, I mean, functions nested in var Upload. What is Upload? What is his type? Not so long ago, familiar with js and never seen this before. - R. Matveev
  • What is Upload? What is his type? This is all you need to write in the question, along with all the details. There are no telepaths here - hindmost
  • @hindmost, comments are used to clarify or clarify a question. If I did not write this right away, then I did not know that this information was necessary. - R. Matveev
  • What is Upload? What is his type? - Property - Grundy

1 answer 1

 if (!window.Upload) { // Ссли Π½Π΅Ρ‚ глобальной ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ Upload Ρ‚ΠΎ выполняСм ΠΊΠΎΠ΄ дальшС var Upload = { // Π‘ΠΎΠ·Π΄Π°Ρ‘ΠΌ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ Upload init: function(obj, vars, options) { // Ѐункция ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ //... }, deinit: function(iUpload) {// Ѐункция уничтоТСния //... } }; } 

Call functions like this:

 var iUpload = Upload.init(obj, vars, options); // Π˜Π½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π»ΠΈ iUpload Upload.deinit(iUpload); // Π£Π½ΠΈΡ‡Ρ‚ΠΎΠΆΠΈΠ»ΠΈ iUpload 

Upload is an object.

  • And what is Upload? How to call him? This is something like a class, I understand correctly? - R. Matveev
  • This is either an object or a class. If you add context, I can say more - Mihanik71
  • 2
    @ R.Matveev, this is an object already. There are no classes in ws yet, there are prototypes and in es6 there is a similarity of the familiar oop syntax. - DanielOlivo
  • Well, I mean that an object can be used as an object - simply as a set of functions, or it can be β€œa class (prototype)” - Mihanik71
  • @ Mihanik71, oh, those js - terminology difficulties - Grundy