Does jQuery or JavaScript have the concept of classes and objects?

前端 未结 7 1040
故里飘歌
故里飘歌 2021-01-30 00:28

I found the following code somewhere, but I am not understanding the code properly.

ArticleVote.submitVote(\'no\');return false;

Is Arti

相关标签:
7条回答
  • 2021-01-30 00:54

    Certainly JS has objects and classes, but it's not exactly a conventional approach.

    It's rather a broad question, but there's three main things you want to know about objects and classes in JS:

    1). Everything is an object - this famously includes JS's first class functions

    2). There are object literals

    var myObject = { "foo": 123, "bar": [4,5,6] };
    

    3). Inheritance is prototype based, so creating classes is more a matter of form than function. To get the effect of a class you'd write something like:

    function myClass(foo)
    {
      this.foo = foo;
    }
    myClass.prototype.myFooMethod = function() {alert(this.foo);}
    
    var myInstance = new myClass(123);
    
    myinstance.myFooMethod(); // alerts 123
    

    For your example it's likely that ArticleVote is an object instance and probably not conceptually a class, and submitVote would be a method of the object. can't tell for sure though, it could be what you'd call a static method in another language.

    0 讨论(0)
提交回复
热议问题