Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UML for javascript?

I'm looking for a way of graphically representing javascript objects...

I know there is UML, but for example, how to represent the chain between 2 objects, eg:

var a, b;

a = {};
b = Object.create(a);

Intuitively, I'd draw something like this:

+-----+
|b    |
|-----|
|     |
+--+--+
   |     +-----+
   +---->|a    |
         |-----|
         |     |
         +-----+

but is there a decent representation in UML?

And what about mixins?

c = $.extend({}, a, b)

+-----+           +-----+
|a    |           |b    |
|-----|           |-----|
|     |<----------|     |
+-----+           +-----+
   +     +-----+
   |     |c    |
   |     |-----|
   +---->|     |
         +-----+
like image 949
abernier Avatar asked Jan 18 '12 22:01

abernier


People also ask

Does JavaScript use UML?

Does JavaScript use UML? Provides support for UML class diagrams in IntelliJ-based IDEs for JavaScript and TypeScript languages. The following features are available: Support for JS and TS classes, interfaces and enums.

What is UML diagram in JavaScript?

Uml Class Diagram Shapes Class diagram is used to represent the static view of an application. The class diagrams are widely used in the modelling of object oriented systems because they are the only UML diagrams which can be mapped directly with object-oriented languages.

Can NetBeans generate UML?

You can create UML project for any of your Java project in NetBeans. Note that one Java project can associate with at most one UML project and you cannot create UML project without associating it with any Java project. Once you have created a UML project for a Java project, you cannot remove it or de-associate it.

What is Nomnoml?

Welcome to nomnomlA tool for drawing UML diagrams based on a simple syntax. Try and edit the code on the left and watch the diagram change. Any changes are saved to the browser's localStorage, so your diagram should be here the next time, (but no guarantees).


2 Answers

First thing you need to know is that JavaScript uses prototype-based inheritance. This means there is no distinction between classes and instances as in other OO languages (like Java). There are just objects. One implication of that is that differentiating between class and object diagrams does not make sense.

To your first example:

var a, b;

a = {};
b = Object.create(a);

This is inheritance - object b inherits properties of object a.

Correct way to model this in UML is this class/object diagram:

object b inherits from object a

Mixins can be viewed as a form of multiple inheritance, object c is inheriting properties from object a and b, diagram for that might look like this:

object c inherits from a and b

like image 104
romario333 Avatar answered Sep 27 '22 16:09

romario333


It looks like you are trying to show the relationship between object instances in a class diagram. This will not really work; you probably want to try using a UML instance diagram (may also be called an object diagram). A class diagram is meant to capture system concepts, their structure and their relationships in a static way. It may help to start with a class diagram and then move to an instance diagram where you can plug some values in the "slots" or properties of you object instances to see if the model in your class diagram works.

like image 43
RobertMS Avatar answered Sep 27 '22 18:09

RobertMS