Difference between revisions of "JQuery"

From Klenwell Wiki
Jump to navigation Jump to search
(Created page with "== Overview == In deference to the [https://en.wikipedia.org/wiki/KISS_principle KISS principle], I generally prefer to use [https://jquery.com/ jQuery] over some of the newer...")
 
(Plugin Pattern)
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
 
In deference to the [https://en.wikipedia.org/wiki/KISS_principle KISS principle], I generally prefer to use [https://jquery.com/ jQuery] over some of the newer more complex frontend frameworks if at all possible. For most CRUD applications, jQuery usually fits the bill.
 
In deference to the [https://en.wikipedia.org/wiki/KISS_principle KISS principle], I generally prefer to use [https://jquery.com/ jQuery] over some of the newer more complex frontend frameworks if at all possible. For most CRUD applications, jQuery usually fits the bill.
  
When writing jQuery code, it should follow one of the following patterns:
+
When writing jQuery code, I usually adopt one of the following patterns:
  
 
* Module: https://learn.jquery.com/code-organization/concepts/#the-module-pattern
 
* Module: https://learn.jquery.com/code-organization/concepts/#the-module-pattern
Line 19: Line 19:
 
To build your own classic jQuery plugin that can be used like so:
 
To build your own classic jQuery plugin that can be used like so:
  
<pre>$('.div').foo()</pre>
+
<pre>$('.div').myPlugin()</pre>
  
 
Boilerplate template to get you started here:
 
Boilerplate template to get you started here:
  
 
* https://github.com/jquery-boilerplate/jquery-boilerplate/blob/master/src/jquery.boilerplate.js
 
* https://github.com/jquery-boilerplate/jquery-boilerplate/blob/master/src/jquery.boilerplate.js

Latest revision as of 15:46, 9 October 2020

Overview

In deference to the KISS principle, I generally prefer to use jQuery over some of the newer more complex frontend frameworks if at all possible. For most CRUD applications, jQuery usually fits the bill.

When writing jQuery code, I usually adopt one of the following patterns:

Another more specialized pattern is the web widget pattern. This would be used to build a centralized widget pushed out to multiple sites (e.g. Disqus comment forms).

Module Pattern

The module is best used for modules where the abstraction is centralized and does not require multiple instantiations (as with a class object).

For an example of the modular pattern, see the following :

Plugin Pattern

To build your own classic jQuery plugin that can be used like so:

$('.div').myPlugin()

Boilerplate template to get you started here: