Wednesday, 21 August 2013

javascript class object, method in keyevent doesnt works

javascript class object, method in keyevent doesnt works

why the method1 is work when direct in init but doesnt work when trigger
by keyevent. on 32,39 keyevent it doesnt works, but on keyevent 37 it
works. so, the function is should work. init function in function also
works, for example hen i init method2, while method is running method1.
this is works. but why when keyevent it doesnt work? where is the problem
function myClass(){
this.method1 = function method1(word){
alert(word)
}
this.method2 = function method2(word){
this.method1(word);
}
this.shortcutKey = function shortcutKey(){
document.onkeydown = function(event){
if( event.keyCode==32 ||
event.keyCode==39 )
{
this.method1("undirect");
}else if(event.keyCode==37){
}
}
}
this.init = function init(){
this.method2("direct init");
this.shortcutKey();
}
this.init();
}
var object = new myClass();

No comments:

Post a Comment