¿Cuál es el propósito de jQuery.fn [duplicado]

Posible duplicado:
¿Qué significa jQuery.fn?

Part of the jQuery source code states:

jQuery.fn = jQuery.prototype = {

Given this, wouldn't

$.fn.adamPlugin = function(options) {  
   return this.each(function() {   });  
};

Be identical to

$.prototype.adamPlugin = function(options) {  
   return this.each(function() {   });  
};  

If so, what's the point of $.fn? Adding things to a prototype is fairly common in JavaScript, so I can't quite understand why the jQuery folks would try to abstract this away.

preguntado el 31 de enero de 12 a las 16:01

I'd imagine the short-hand allows them to make the library smaller... also, I hear they're big proponents of writing less. -

Why $ for jQuery? Replacing the one with the other is identical, too. -

Paul Irish explains it a little aquí también. -

@antisanity: That's probably it. In addition, a minifier could not rename the prototype property as it is a special name, but it could rename fn. -

@antisanity - that's it. It makes the library size smaller, and is friendlier to minifiers. Can you put that as an answer before this question gets closed? -

1 Respuestas

It's just a convenient alias for prototype eso es todo.

Respondido el 31 de enero de 12 a las 20:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.