0
としてイベントオブジェクトを渡すときIいる(略して)次のオブジェクトコード:エラー引数
var codeEditor = function() {
...
// The non-highlighted code.
this.unhighlightedCode = null;
...
// "this" object
var that = this;
this.keys = function(e) {
switch (e.keyCode) {
default:;
}
};
// Initialization
this.init = function() {
...
that.unhighlightedCode = document.getElementById("unhighlightedCode");
that.unhighlightedCode.onkeydown = that.keys(event);
}();
}
// The implementaion
var editor = new codeEditor;
問題:この行that.unhighlightedCode.onkeydown = that.keys(event);
で
イベントオブジェクトを渡します。
結果:
Firefoxの場合、、Chromeの場合はUncaught TypeError: Cannot read property 'keyCode' of undefined
のエラーメッセージが表示されます。