UNPKG

916 BJavaScriptView Raw
1
2//
3// # IperElement
4//
5// Base class for *iper*.
6//
7
8var _ = require('underscore')
9
10//
11// ## Constructor
12//
13// Do not use *IperElement* directly, it is used internally by *iper* as a base class.
14//
15// If `this` refers to an *iper* class instance
16//
17// ```
18// IperElement.call(this, graph)
19// ```
20//
21
22function IperElement (graph) {
23
24 //
25 // ## Attributes
26 //
27
28 //
29 // ### graph
30 //
31 // References the graph containing the element.
32 //
33
34 /* check graph */
35
36 if (_.isUndefined(graph))
37 throw new Error('graph is not defined')
38
39 Object.defineProperty(this, 'graph', {
40 enumerable: false,
41 value: graph,
42 writable: false
43 })
44
45 //
46 // ### id
47 //
48 // Every IperElement has a unique id.
49 //
50
51 Object.defineProperty(this, 'id', {
52 enumerable: true,
53 value: _.uniqueId(),
54 writable: false
55 })
56}
57
58module.exports = IperElement
59