-// 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) {
}
};
+/**
+ * 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) {
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;
-}*/