X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Feuphorik.js;h=d2cd248bc462e257a346f46985b269857a9de30e;hp=28cba42f848e6c73878136ecf6803c7894c8c2a8;hb=a427cabd1a5f3fba6650157913b113164d70ffc0;hpb=deff7a2f11dca2b300b258d1e93d71e3b2e34c84 diff --git a/js/euphorik.js b/js/euphorik.js index 28cba42..d2cd248 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -67,16 +67,22 @@ var euphorik = {} Object.prototype.each = function(f) { for (var k in this) { if (this.hasOwnProperty(k)) { - f(k, this[k]) + f(k, this[k]); } } -} +}; Array.prototype.each = function(f) { for (var i = 0; i < this.length; i++) { - f(i, this[i]) + f(i, this[i]); } -} +}; + +Array.prototype.map = function(f) { + for (var i = 0; i < this.length; i++) { + this[i] = f(this[i]) + } +}; String.prototype.trim = function() { return jQuery.trim(this) // anciennement : this.replace(/^\s+|\s+$/g, ""); @@ -88,7 +94,35 @@ String.prototype.ltrim = function() { 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; +} + ///////////////////////////////////////////////////////////////////////////////////////////////////