From a427cabd1a5f3fba6650157913b113164d70ffc0 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Fri, 18 Jul 2008 07:34:21 +0000 Subject: [PATCH] =?utf8?q?ADD=20fonctions=20pour=20l'h=C3=A9ritage?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- js/euphorik.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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; +} + /////////////////////////////////////////////////////////////////////////////////////////////////// -- 2.45.2