X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Fbetterjs.js;h=b4d0bb6d4ae929a249aa42263679619e61486e3f;hp=30ca5ad70f9fc6f33c4a9a28f2fc4a1b74e128ab;hb=5d9992368bb386d2e606ae037c5478fe10ac70e8;hpb=6c0fcdfaefd072f8b0ee1d7d8f1ba2a2c1ede8ec diff --git a/js/betterjs.js b/js/betterjs.js index 30ca5ad..b4d0bb6 100644 --- a/js/betterjs.js +++ b/js/betterjs.js @@ -1,10 +1,12 @@ -// tout un tas d'améliorations de JavaScript ;) - +// coding: utf-8 +// some improvements for JavaScript /** - * Pour chaque propriété de l'objet execute f(p, v) ou p est le nom de la propriété et v sa valeur. - * Ne parcours pas les propriétés des prototypes. - * FIXME : Normalement : Object.prototype.each = function(f) mais non supporté par jquery + * For each object properties execute f(p, v) where p is the propertie name and v its value. + * Does not traverse the protypes properties. + * FIXME : Should be "Object.prototype.each = function(f)" but doen't supported by jQuery. + * @o The object. + * @f The function f(p, v). */ //Object.prototype.each = function(f) { var objectEach = function(o, f) { @@ -15,6 +17,11 @@ var objectEach = function(o, f) { } }; +/** + * Return the number of properties of a given object. + * Does not count the prototypes properties. + * @o The object. + */ var objectMemberCount = function(o) { var nb = 0; for (var k in o) { @@ -25,34 +32,52 @@ var objectMemberCount = function(o) { return nb; }; +/** + * Call a function to all value of the Array. + * @f The function f(i, v) where i is the index and v the value. + */ Array.prototype.each = function(f) { for (var i = 0; i < this.length; i++) { f(i, this[i]); } }; +/** + * Map a function to all value of the Array. + * @f The function f(v) -> v' where v is the old value and v' the new one. + */ Array.prototype.map = function(f) { for (var i = 0; i < this.length; i++) { this[i] = f(this[i]); } }; +/** + * Remove all space character (space, tab) at the begining and the end of the String. + */ String.prototype.trim = function() { return jQuery.trim(this); // anciennement : this.replace(/^\s+|\s+$/g, ""); -} +}; +/** + * Remove all space character (space, tab) at the begining of the String. + */ String.prototype.ltrim = function() { return this.replace(/^\s+/, ""); }; +/** + * Remove all space character (space, tab) at the end of the String. + */ String.prototype.rtrim = function() { return this.replace(/\s+$/, ""); }; /** - * Voir : http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html + * (Not use for the moment) + * See : http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html * - * Exemple : + * Example : * * function Mammal(name) { * this.name = name;