2 // some improvements for JavaScript
5 * For each object properties execute f(p, v) where p is the propertie name and v its value.
6 * Does not traverse the protypes properties.
7 * FIXME : Should be "Object.prototype.each = function(f)" but doen't supported by jQuery.
9 * @f The function f(p, v).
11 //Object.prototype.each = function(f) {
12 var objectEach = function(o
, f
) {
14 if (o
.hasOwnProperty(k
)) {
21 * Return the number of properties of a given object.
22 * Does not count the prototypes properties.
25 var objectMemberCount = function(o
) {
28 if (o
.hasOwnProperty(k
)) {
36 * Call a function to all value of the Array.
37 * @f The function f(i, v) where i is the index and v the value.
39 Array
.prototype.each = function(f
) {
40 for (var i
= 0; i
< this.length
; i
++) {
46 * Map a function to all value of the Array.
47 * @f The function f(v) -> v' where v is the old value and v' the new one.
49 Array
.prototype.map = function(f
) {
50 for (var i
= 0; i
< this.length
; i
++) {
56 * Remove all space character (space, tab) at the begining and the end of the String.
58 String
.prototype.trim = function() {
59 return jQuery
.trim(this); // anciennement : this.replace(/^\s+|\s+$/g, "");
63 * Remove all space character (space, tab) at the begining of the String.
65 String
.prototype.ltrim = function() {
66 return this.replace(/^\s+/, "");
70 * Remove all space character (space, tab) at the end of the String.
72 String
.prototype.rtrim = function() {
73 return this.replace(/\s+$/, "");
77 * (Not use for the moment)
78 * See : http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html
82 * function Mammal(name) {
86 * Cat.Inherits(Mammal);
87 * function Cat(name) {
88 * this.Super(Mammal, name);
91 /*Object.prototype.Super = function(parent) {
92 if(arguments.length > 1) {
93 parent.apply( this, Array.prototype.slice.call( arguments, 1 ) );
98 Function.prototype.Inherits = function(parent) {
99 this.prototype = new parent();
100 this.prototype.constructor = this;