JQuery as custom functions

I was wondering how I can create features like jQuery. For instance:$(ID).function()

If the identifier is the identifier of the HTML element, $this is a function that returns the document.getElementById link of the "ID" element, and the function is a javascript custom function.

I am creating a small library that implements some functions. And I want to use this syntax without using jQuery.

Now my questions are: how can I implement this? What is the name of the flow that allows this?

Edit:

I want to do the following:

HTMLElement.prototype.alertMe = function () {alert (this.value);}

Then, when I call document.getElementById('html_input_id').alertMe(), it should show a warning with an input value. But

+3
source share
3
$ = function(id) {
    return document.getElementById(id);
}
+1

, , , . jQuery , ; Javascript, O'Reilly.

$ - JS, , , :

var $ = function(args){...}

, , .

var EstebansLibrary = function(args){...}
var $ = EstebansLibrary; // make an alias

, , JS - arguments.

, ; , -

var EstebansLibrary = (function(){
    // process the arguments object
    // do stuff
    return {
       opname : implementation,...
    }
})();

, , , , prototype.

+1

.

Element.prototype.testFunction = () {Alert ()};

testFunction HTML.

, Array, String ..

- , , , IE. , , MooTools jQquery, DOM , .

0

All Articles