-2

I would like to know how I can do this...

function action(param)
{
   $(body).param('Blah');
}

action('append');

If you understood me, is there any way of that happening?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Jhonatan G.
  • 97
  • 1
  • 3
  • 11

1 Answers1

0

Functions are first-class objects in JavaScript. You should just pass in the function, and use apply to invoke it on $('body'), rather than passing in a string which may or may not actually point to a function:

function action(fn) {
  fn.call($('body'), 'Blah');
}

action($.fn.append);
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
user229044
  • 232,980
  • 40
  • 330
  • 338
  • Ah, yes, I forgot that "instance" methods applying to specific sets of elements aren't available via the global jQuery object. Thanks. – user229044 Dec 09 '13 at 12:53