From: Greg Burri Date: Fri, 18 Jul 2008 07:34:21 +0000 (+0000) Subject: ADD fonctions pour l'héritage X-Git-Tag: 1.1.0~73 X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=a427cabd1a5f3fba6650157913b113164d70ffc0;p=euphorik.git ADD fonctions pour l'héritage --- diff --git a/js/euphorik.js b/js/euphorik.js index 8c13841..d2cd248 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -94,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; +} + ///////////////////////////////////////////////////////////////////////////////////////////////////