I would like to know what the apply()
function in jquery is for.
I'm creating a plugin where I'm using. By observation I see that it takes this
and passes as argument in function init
. Then I can use this
instead of opcao
in function.
But I would like to know who you know, what is the real function, and when should I use it?
(function( $ ){
var methods = {
init:function(opcao){
this.find("input").each(function(i,v){
console.log(i);
console.log($(v).appendTo("p"));
});
},
}
$.fn.input = function(method) {
console.log(this)
return methods.init.apply( this, arguments );
};
})( jQuery );