I want to pass the currently called object with it’s currently set parameters on to a closure function. I’m not sure how to do this in general, but then I think jQuery adds another layer of confusion because this refers to an element.
Example:
jQuery Plugin
(function( $ ){
$.fn.addContentType = function(obj) {
var name = "this is just an example";
obj.func.call(this); //<--I want to pass this object, not the jQuery selector
};
})( jQuery );
Call to Plugin
jQuery("#someelement").addContentType({
func:function(){
console.log(this.name); //<--Expect "this is just an example"
}
});
Any ideas how to do this?
This is just an example and doesn’t do anything, I’m just trying to show what I’m after. If I am missing details, let me know.
To access
nameas a property of the jQuery object, you’d need to add it instead of using a variable.Or use the variable to pass the value to the function:
and receive it on the other end:
Or to make your
objthethisvalue, do this:…but you still need to pass the argument unless you assign the value as a property to
obj.