So, lets say I have a function like this
(function($){
$.fn.test = function(opts){
var _object = $(this),
_opts = $.extend({}, $.fn.test.defaults, opts),
_callback = _opts.objects[1].callback
/* some code here */
_callback() /* calling for a callback */
}
$.fn.test.defaults = {
/* not that important for now */
}
})
That's how I initialise that function
$('.element').test({
option: 0, /* not important */
variable: 1, /* not important */
objects: [
{
"object" : ".element2",
"callback" : false
},
{
"object" : ".element3", /* THIS IS OBJECT № 2 */
"callback" : function(){
/* >>> {THIS PART} <<< */
console.log (this)
}
},
]
So on {THIS PART} it just returns the data of object №2, but I would like the callback function to run on my _object element from $.fn.test so it would output the data of $('.element'). I can't make it hardcoded, and can't put instead console.log (this) just console.log ($('.element')) - as I'm trying to make more dynamic function. So I need to replace this with my _object element at the moment when it's calling for a callback right here _callback() /* calling for a callback */ . I definitely can't use replace as it's not a string, but I had an idea to convert function to a string, change what I need and then convert to function - but that sounds like inappropriate solution.
Do you have any ideas in your mind? What can you suggest?
Thank you in advance.