0

I'm trying to add a method via prototype but getting an error. Any idea what is going wrong?

function Graph() {
  // Code
}

Graph.prototype.render = function() {
  // Code
}

var test_graph = new Graph;
test_graph.render(); // Returns error that function Graph.render isn't defined.
Don P
  • 60,113
  • 114
  • 300
  • 432
  • 2
    You must've left out some important code. This works fine in jsFiddle: http://jsfiddle.net/AEXFE/ – Justin Niessner Nov 08 '13 at 19:09
  • Maybe you call the render function from a different object (timeout or event handler). Check out this answer what `this` can be: http://stackoverflow.com/a/16063711/1641941 (posted in your other question as well) To debug; try to console.log stuff like `this`. For example: `console.log("in render, this is now:",this);` Preferably use Chrom or Firefox with firebug plugin and press F12 to open the dev tools. Your console.log statements should show up in the console tab and you can click on logged objects to inspect them. – HMR Nov 08 '13 at 19:21

0 Answers0