4
I wonder what the function is for apply()
in jquery.
I am creating a plugin where I am using. By observation I see that it catches the this
and passes as argument in function init
. Then I can use the this
instead of opcao
in function.
But I’d like to know who you know, what your real job is and when to 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 );
So if I add parameters in the function, in the case of the object with default values, they will stay the same. Hence the defauts parameters I can leave inside the object>: methods. I will not need to create another object within $.fn.input .. ATT
– abcd