Reputation: 355
I declare the following object :
var Node = {
nodeID: '',
parentID: '',
nodeName: '',
children: []
}
and I'd like to write a Contains()
function to check if the children
array contains a specific Node
object, used like Node.Contains(otherNode)
.
Where and how should I declare it to be able to use this syntax ?
Upvotes: 0
Views: 193
Reputation: 152216
Just declare this function next to the other properties:
var Node = {
nodeID: '',
parentID: '',
nodeName: '',
children: [],
Contains: function(otherNode) {
return this.children.indexOf(otherNode) > -1;
}
}
Upvotes: 1