A quoi sert et d'où vient prototype dans ce code ?
Bonjour tout le monde,
J'ai du code javascript et je me demandais ce que voulais dire prototype dans ce code et d'où il vient ?
J'ai fait une recherche dans mes autres documents sans trouver trace de ce prototype.
Voici le code en quesiton :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| function CMatrice(NL,NC)
{
// MEMBRES DE LA CLASSE CMatrice
this.NL = 0;
this.NC = 0;
this.Valeurs = null;
// CONSTRUCTEUR DE LA CLASSE CMatrice
this.Dimensionner(NL,NC);
}
CMatrice.prototype.Dimensionner = function(NL,NC)
{
//if ( (NL == undefined) || (NC == undefined) ) return false;
//si le type de NL ou de NC est différent de nombre, on sort de la fonction
if ( (typeof NL != "number") || (typeof NC != "number") ) return false;
//si NC ou NL est négatif, on sort de la fonction
if ( (NL < 1) || (NC < 1) ) return false;
//if ( (this.NL != parseInt(NL)) || (this.NC != parseInt(NC)) ) return false;
this.NL = parseInt(NL);
this.NC = parseInt(NC);
this.Valeurs = new Array(null);
for (var il=1; il <= this.NL; il++)
{
this.Valeurs[il] = new Array(null);
for (var ic=1; ic <= this.NC; ic++) this.Valeurs[il][ic] = 0;
}
return true;
}
CMatrice.prototype.Serialiser = function(sep_cellule,sep_ligne)
{
if (typeof sep_cellule != "string") sep_cellule = "\t";
if (typeof sep_ligne != "string") sep_ligne = "\n";
var Resultat = "";
Resultat += this.NL + sep_ligne + this.NC + sep_ligne;
if (this.NL == 0) return Resultat;
for (var il=1; il <= this.NL; il++)
{
for (var ic=1; ic < this.NC; ic++) Resultat += this.Valeurs[il][ic] + sep_cellule;
Resultat += this.Valeurs[il][this.NC] + sep_ligne;
}
return Resultat;
}
CMatrice.prototype.Deserialiser = function(Donnees,sep_cellule,sep_ligne)
{
if (typeof Donnees != "string") return false;
if (typeof sep_cellule != "string") sep_cellule = "\t";
if (typeof sep_ligne != "string") sep_ligne = "\n";
var Lignes = Donnees.split(sep_ligne);
if (Lignes.length < 3) return false;
if (!this.Dimensionner(parseInt(Lignes[0]),parseInt(Lignes[1]))) return false;
for (var il=1; il <= this.NL; il++)
{
var Cellules = Lignes[il+1].split(sep_cellule);
if (Cellules.length != this.NC) return false;
for (var ic=1; ic <= this.NC; ic++) this.Valeurs[il][ic] = parseFloat(Cellules[ic-1]);
}
return true;
} |
Merci d'avance.
beegees