Object orientation with jQuery / JavaScript

1

I have read several things about this, and I came to this conclusion, example:

   var classe = function () {
        var metodo = function () {
            return 0;
        }
        return {
            init: function () {
                metodo();
            }
        };
    }();

    jQuery(document).ready(function () {
       classe.init();
    });

First:

  

Is this the correct way to instantiate classes / methods in javascript? If not, how would the correct form be?

Second:

jQuery methods are called in a cadenced form:

$('#elemento').show().html('<html></html>').append('<div></div>').addClass('exemplo');
  

Does jQuery natively (without doing functions, just the original methods) can be considered an object orientation?

    
asked by anonymous 19.09.2017 / 22:27

2 answers

1

It's interesting to think of J-query as an ally of javascript in object orientation, but it makes no sense to mix J-query into things that are not related to DOM manipulation and event manipulation.

Think of things like Inheritance, polymorphism, abstraction, encapsulation. J-query would only disrupt, because it is only a library that provides native language methods.

In relation to the class, there are also a multitude of ways to instantiate it, each with its particularity.

Worth reading Unpacking the javascript language

    
19.09.2017 / 23:08
1

That's correct. But I would make the following observation. For instance, you should use new Classe().init() But it is not the only way. You can also use the prototype as an aid. will be useful to you.

Regarding object orientation. today I do not believe js is OO. However, I believe that it makes use of objects and in a cadenced form, which enhances the use of language.

Today I believe the great advantage in JS is in this "racing" way of programming.

    
19.09.2017 / 22:58