Suppose I have this code:
function Graph() {
this.vertices = [];
this.edges = [];
}
Graph.prototype = {
addVertex: function(v){
this.vertices.push(v);
}
};
Is it possible to add the addVertex property name inside function Graph() and thus eliminate the second part of this code altogether (from where Graph.prototype = begins)? I've tried this but it doesn't work:
function Graph() {
this.vertices = [];
this.edges = [];
addVertex = function(v){
this.vertices.push(v);
};
}