icecats11 / js-hotkeys

Automatically exported from code.google.com/p/js-hotkeys
0 stars 0 forks source link

Ability to add an execution scope to the callback function #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. try to use 'this.something' in function call

What is the expected output? What do you see instead?
I can use 'this' to reference the caller.

Example:
foo = {
    id: 5,
    bar: function() {
        alert(this.id);
    },
    init: function() {
        uic.shortcut.add("Shift+V", this.bar, {}, this, true);
    }
}

foo.init();

What version of the product are you using? On what operating system?
current

Please provide any additional information below:
http://www.openjs.com/scripts/events/keyboard_shortcuts/

See comment of Patrick ( 28 Aug, 2007 12:49 ). He proposed a solution for 
the script on that page. It should be possible to adapt this for js-
hotkeys.

Original issue reported on code.google.com by gra...@gmail.com on 30 Nov 2007 at 1:00

GoogleCodeExporter commented 8 years ago
the following works with this.xxx approach.
I guess you don't pass the parameters correctly

function domo(){
    foo.bar();
}            
jQuery(document).ready(domo);

var foo = {
    baz: function (){jQuery('#_Shift_n').addClass('dirty')},
    bar: function(){jQuery.hotkeys.add('Shift+n', this.baz);}
}

Original comment by Afro.Sys...@gmail.com on 6 Jan 2008 at 9:47