Callum Linington Callum Linington - 4 months ago 7x
Javascript Question

Extending jQuery writing Plugins

When you write a plugin for jQuery you do:

(function ($) {
$.fn.myFunc = function () {


I expect that the
allows the functions below to be assigned to it.
are a list of the functions that are allowed to be executed.

I'm not sure what jQuery does, I think it still allows you to use

How do you achieve something like this, but for just plain javascript, no libraries?

I carry a single javascript file between all my web pages.

Here's the question: I want to be able to use a set of custom functions really easily, like jQuery can.

For example in jQuery:


I want to be able to do something like:


is my own custom what ever symbol, and I can also attach other functions to it.

The main idea, is to achieve something that cannot interfere with other things written, so clashing functions etc.


To use $.yourfunction, you need to extend $

$.fn permits to extend $('selector').your function

Here is a working exemple :

(function ($) {
    $.fn.myFunc1 = function (text) {

    $.myFunc2 = function (text) {