In trying to call a method on the CodeMirror javascript code editor. I’m new to javascript and trying to understand how object oriented stuff works. I’m having problems calling what I believe are methods. For instance,
var editor = CodeMirror.fromTextArea('code', options);
editor.grabKeys(function(e) { alert("Key event");});
This gives the Uncaught TypeError: Cannot call method 'grabKeys' of undefined. Looking at the editor object reveals that grabKeys seems to be located at editor.__proto__.grabKeys.
How should I be thinking about this?
Probably yoour code should be something like this:
Notice the ‘new’ operator..
Here is a good explanation of what prototype method calls are for:
http://www.javascriptkit.com/javatutors/proto.shtml