What is the difference between a JavaScript object and an OO / UML / Java object?

In standard OO, as defined by UML and Java, there is a specific concept of an object. What is the difference between this classic concept of objects and a JavaScript object?

+4
source share
1 answer

JavaScript objects are different from classic OO / UML objects (C ++ / Java / C #, etc.). In particular, they should not instantiate the class . And they can have their own instance level methods in the form of method slots, so they have not only (regular) property slots , but also method slots . In addition, they may also have keyword slots . Thus, they can have three different slots, while classic objects (called instance specifications) in UML) have only property slots.

JavaScript objects can be used in many ways for different purposes. Here are five different uses or possible values ​​for JavaScript objects:

  • A , , ,

    var myRecord = { firstName:"Tom", lastName:"Smith", age:26}
    
  • ( '-') . , , ,

    var numeral2number = { "one":"1", "two":"2", "three":"3"}
    

    "1" "", "2" "" .. JavaScript, (, ).

  • . , ,

    var person1 = {  
      lastName: "Smith",  
      firstName: "Tom",
      getInitials: function () {
        return this.firstName.charAt(0) + this.lastName.charAt(0); 
      }  
    };
    
  • , , . , Model-View-Controller (MVC), , MVC:

    var myApp = { model:{}, view:{}, ctrl:{} };
    
  • A o, , JavaScript C,

    var o = new C(...)
    

    /

    o.constructor.name  // returns "C"
    

JavaScript . JavaScript Sumary.

+7

All Articles