简体   繁体   English

JavaScript是否具有类关系?

[英]Does JavaScript have class relationships?

In school, I have been taught that Java has class relationships (is-a and has-a). 在学校里,我被告知Java具有类关系(is-a和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. 我必须显示一个项目的两种类型的关系,但是我决定使用Java解析我得到的数据,然后使用网页显示该数据的可视化。 So can I show is-a and has-a relationships in JavaScript? 那么我可以在JavaScript中显示is-a和has-a关系吗?

--edit-- - 编辑 -

I already have a Java program that creates an object out of the data I have been given. 我已经有一个Java程序,可以根据给出的数据创建一个对象。 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? 这就是JavaScript的用武之地。这有意义吗? Or am I doing this the really hard way? 还是我真的很难做到这一点?

Javascript doesn't really work explicity with Object relation ships of is, has a. Java与is的Object关系无关,具有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. 但这与Java中的语法不太一样,所有内容都在javascript中的Object中,并且类型很弱。 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. JavaScript具有原型关系,它们与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. 一个对象仍然可以继承另一个对象,因此没有理由不能按照has-a和is-a关系查看对象。

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. 两种对象模型之间的区别在于关系的定义方式以及JavaScript在类定义之后添加函数方面提供的灵活性(不一定是一件好事)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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