简体   繁体   中英

Does JavaScript have class relationships?

In school, I have been taught that Java has class relationships (is-a and has-a). I am required to show both types of relationships for a project however I have decided to use Java to parse data I have been given and then use a webpage to display a visualization of said data. So can I show is-a and has-a relationships in JavaScript?

--edit--

I already have a Java program that creates an object out of the data I have been given. I will have the program open a webpage when it is done that will visualize the data. That is where the JavaScript comes in. Does that make sense? Or am I doing this the really hard way?

Javascript doesn't really work explicity with Object relation ships of is, has a. You don't have scope modifiers like private, protected, public, although there are several methods to mimic these kinds of behaviors. Objects can still inherit from each other, and you can create aggregation's. But this isn't quite the same syntax as in java, also everything is in Object in javascript and it's weakly typed. It isn't quite the same for some things but you can simulate this. Cheers.

JavaScript has prototypical relationships, which are similar, but subtly different from class relationships in Java.

An object can still inherit from another object and there is no reason why could not view objects in terms of has-a and is-a relationships.

The differences between the two object models come down to how the relationships are defined and the flexibility (which is not necessarily a good thing) that JavaScript offers in terms of adding functions after class definition.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM