X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Fbetterjs.js;h=41d62235b169b43af4a124d7b8154b9a772a1886;hp=30ca5ad70f9fc6f33c4a9a28f2fc4a1b74e128ab;hb=HEAD;hpb=6c0fcdfaefd072f8b0ee1d7d8f1ba2a2c1ede8ec diff --git a/js/betterjs.js b/js/betterjs.js index 30ca5ad..41d6223 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,52 +32,43 @@ 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 - * - * Exemple : - * - * function Mammal(name) { - * this.name = name; - * } - * - * Cat.Inherits(Mammal); - * function Cat(name) { - * this.Super(Mammal, name); - * } - */ -/*Object.prototype.Super = function(parent) { - if(arguments.length > 1) { - parent.apply( this, Array.prototype.slice.call( arguments, 1 ) ); - } else { - parent.call( this ); - } -} -Function.prototype.Inherits = function(parent) { - this.prototype = new parent(); - this.prototype.constructor = this; -}*/