Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does jQuery.fn mean?

What does the fn here mean?

jQuery.fn.jquery 
like image 964
ajsie Avatar asked Nov 03 '10 00:11

ajsie


People also ask

What does FN stand for in coding?

The Fn key, short form for function, is a modifier key on many keyboards, especially on laptops, used in a compact layout to combine keys which are usually kept separate.

What does the $() mean in jQuery?

In jQuery, the $ sign is just an alias to jQuery() , then an alias for a function. This page reports: Basic syntax is: $(selector).action() A dollar sign to define jQuery.

What does $( function ()) short hand do?

It's just shorthand for $(document). ready() , as in: $(document). ready(function() { YOUR_CODE_HERE }); Sometimes you have to use it because your function is running before the DOM finishes loading.

What is FN extend?

fn. extend() method extends the jQuery prototype ( $. fn ) object to provide new methods that can be chained to the jQuery() function.


1 Answers

In jQuery, the fn property is just an alias to the prototype property.

The jQuery identifier (or $) is just a constructor function, and all instances created with it, inherit from the constructor's prototype.

A simple constructor function:

function Test() {   this.a = 'a'; } Test.prototype.b = 'b';  var test = new Test();  test.a; // "a", own property test.b; // "b", inherited property 

A simple structure that resembles the architecture of jQuery:

(function() {   var foo = function(arg) { // core constructor     // ensure to use the `new` operator     if (!(this instanceof foo))       return new foo(arg);     // store an argument for this example     this.myArg = arg;     //..   };    // create `fn` alias to `prototype` property   foo.fn = foo.prototype = {     init: function () {/*...*/}     //...   };    // expose the library   window.foo = foo; })();  // Extension:  foo.fn.myPlugin = function () {   alert(this.myArg);   return this; // return `this` for chainability };  foo("bar").myPlugin(); // alerts "bar" 
like image 147
Christian C. Salvadó Avatar answered Sep 24 '22 22:09

Christian C. Salvadó