Simplify addNodes() even more by using variable number of arguments.
This commit is contained in:
parent
90b23f131e
commit
9ac764d634
|
@ -5,8 +5,8 @@
|
||||||
<script src="springyui.js"></script>
|
<script src="springyui.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var graph = new Graph();
|
var graph = new Graph();
|
||||||
graph.addNodes(['Dennis', 'Michael', 'Jessica', 'Timothy', 'Barbara', 'Franklin'])
|
graph.addNodes('Dennis', 'Michael', 'Jessica', 'Timothy', 'Barbara', 'Franklin')
|
||||||
graph.addNodes(['Monty', 'James', 'Bianca']);
|
graph.addNodes('Monty', 'James');
|
||||||
|
|
||||||
var dennis = graph.newNode({label: 'Dennis'});
|
var dennis = graph.newNode({label: 'Dennis'});
|
||||||
var michael = graph.newNode({label: 'Michael'});
|
var michael = graph.newNode({label: 'Michael'});
|
||||||
|
|
13
springy.js
13
springy.js
|
@ -69,12 +69,13 @@ Graph.prototype.addNode = function(node) {
|
||||||
return node;
|
return node;
|
||||||
};
|
};
|
||||||
|
|
||||||
Graph.prototype.addNodes = function(list) {
|
Graph.prototype.addNodes = function() {
|
||||||
if (typeof(list[0]) == "string") {
|
// accepts variable number of arguments, where each argument
|
||||||
list.forEach(function(name) {
|
// is a string that becomes both node identifier and label
|
||||||
var node = new Node(name, data = {label:name});
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
this.addNode(node);
|
var name = arguments[i];
|
||||||
}, this);
|
var node = new Node(name, data = {label:name});
|
||||||
|
this.addNode(node);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user