701 posts
  • 7 Years of Membership
  • Affiliate Level 1
  • Canada
  • Collector Level 6
chrismccoy
says

im using a popup box when i click a link

which is

$(”#search”).click(function(e) {

but i also want to create a shortcut

$.jQee(‘shift+s’, function(e) {

(shift+s) will open the box, is their anyway to combine them into 1 statement, so i dont have to copy the same function?

2067 posts
  • Collector Level 3
  • 5 Years of Membership
  • Exclusive Author
  • United States
Landonw
says

Why don’t you use “jQuery.bind” ?

415 posts
  • 6 Years of Membership
  • Author Level 5
  • Collector Level 1
  • Exclusive Author
+4 more
osigrandi
says

You could define the inner function as a named function I think:

http://stackoverflow.com/questions/336859/javascript-var-functionname-function-vs-function-functionname

Should save some space at least; too lazy to test, hope it works.

3535 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • United States
+13 more
sevenspark
Moderator
says

Define a single function (with a function name), then just pass that function as a callback instead of using the anonymous function :)

Basic idea: http://jsfiddle.net/sevenspark/ESrS3/

701 posts
  • 7 Years of Membership
  • Affiliate Level 1
  • Canada
  • Collector Level 6
chrismccoy
says

thanks guys, ended up doing the function and calling it

by
by
by
by
by
by