Bonjour,
J'ai ecris un code et je suis assez etonné en testant une méthode (un constructeur)que javaScript tolere le fait d'appeller une méthode sans définir de paramétres formels dans la dite méthode et pourtant les valeurs sont bien passées en paramétre comme le montre la propriété argument.
De plus,si je supprime
this.nomPage=nomPage;
this.id=id;
ma méthode Return ne retourne plus rien.
Donc ça fonctionne.
Est ce normal?
Voici mon codeMerci beaucoup
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <script type="text/javascript"> // le constructeur de l'objet de type classFormEvent function classFormEvent(){ alert("Nombre de paramètres: " + arguments.length); for(var i=0; i<arguments.length; i++) { alert("Paramètre " + i + ": " + arguments[i]); } //if(typeof(nomPage!="undefined")&&(typeof(id!="undefined"))){ this.nomPage = nomPage; this.id = id; // si un parametre nomPage est passé /*} else { this.nomPage = null; this.id = null; }*/ } //on attache la méthode de redirection de la page avec la propriété prototype à l'objet classFormEvent classFormEvent.prototype.Return=function(){ alert(this.nomPage); alert(this.id); //window.location='http://webcreation-lg.fr/update/form.php?page='+nomPageSelect; } classFormEvent.prototype.Submit=function(){ } </script> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <SCRIPT TYPE="TEXT/JAVASCRIPT"> var nomPage = "sample"; var id= "test id"; var namePage = new classFormEvent(nomPage,id); namePage.Return(nomPage,id); </SCRIPT>
Partager