Plugin jQuery: fornire un accesso pubblico alle funzioni secondarie

Plugin jQuery: fornire un accesso pubblico alle funzioni secondarie

Questa funzionalità è un modo interessante per estendere i vostri plugin.

Per esempio un nostro plugin può definire una funzione chiamata format() che formatta il testo.


"use strict";

$.fn.hilight = function( options ) {

    var format = function( txt ) {
    	return "<strong>" + txt + "</strong>";
    };

    $.fn.hilight.format = format;

};

Così facendo la funzione format() diventa a tutti gli effetti un metodo pubblico del nostro plugin e può essere utilizzata anche al di fuori del suo contesto.

Torna su