Last active
August 29, 2015 14:07
-
-
Save NathaTerrien/1cf5cd3b6f1ca3e956c0 to your computer and use it in GitHub Desktop.
Formation 06 -> 10/10/2014 : Excercice JS n°1 : Création module et enrichissement (JS).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// création ou complétion du namespace (?) | |
var Geometry = (function (Geometry) { | |
'use strict'; | |
function Shape() { | |
this.type = "Shape"; | |
}; | |
Geometry.Shape=Shape; | |
Shape.prototype.getType=function (){ | |
//return Shape.type; | |
return "Je suis un(e) " + this.type; | |
}; | |
return Geometry; | |
})(Geometry || {}); | |
// Ajout du module triangle comme si il était déclaré | |
// en complétion de namespace dans un autre fichier par exemple | |
var Geometry = (function (Geometry) { | |
'use strict'; | |
Triangle.prototype = new Geometry.Shape(); | |
// Triangle.prototype.constructor = Triangle; => implicite | |
function Triangle(parA,parB,parC) { | |
this.a= parseInt(parA) || 0; | |
this.b= parseInt(parB) || 0; | |
this.c= parseInt(parC) || 0; | |
this.type = "Triangle"; | |
}; | |
Geometry.Triangle=Triangle; | |
Triangle.prototype.getTypePlus=function (){ | |
// KO : appelle bien la fonction mais variable type "undefined" : | |
// return "Je suis un(e) " + this.type + ", " + this.getType.apply(this.__proto__); | |
// Ok mais insatisfaisant en terme d'héritage/"objet" : | |
return "Je suis un(e) " + this.type + " et aussi un(e) " | |
+ this.__proto__.type + " (par heritage)"; | |
}; | |
Triangle.prototype.getPerimetre=function (){ | |
var peri = this.a + this.b + this.c; | |
return peri; | |
}; | |
return Geometry; | |
})(Geometry || {}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment