Good afternoon people’s
I have built a jquery plugin that I use on my site. The plugin is for suggestive input boxes and works fine.
One thing I need to add to it is the ability to pass a function in it’s config to apply to the response of the ajax call that is made for the suggestive. I can’t find anything on trusty old google about how to pass functions and have them applied in the scope of the plugin..
I need this because some responses update one field and some update 2 or more fields with different text held in the reponse and I dont want to keep duplicating the plugin allowing for this to happen. I am assuming that the javascript method “apply” is what I need to look at but I am totally confused
Does this even make sense on what I am trying to do ? and if so can anyone help or point me in the right direction.
Thanks in advance
Alex
You are looking for
.call()or.apply(). You can pass the context (i.e. scope) as the first parameter to both..call()works like this:While
.apply()works like this:.apply()is very helpful when generating the parameters dynamically.