Bonjour,
j'ai créé une classe avec des membres que j'aimerais garder privées.
Voici le code :
Seulement ce code ne fonctionne pas...
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 function Batiment(name, width, height) { /* Attributes */ var _name = name; var _width = width; var _height = height; /* Methods */ Batiment.prototype = { show : function() { alert("Name : " + _name + " ; size : [" + _width + "," + _height + "]"); } /* Mutators */ setSize : function(width, height) { _width = parseInt(width); _height = parseInt(height); } getWidth : function() { return _width; } getHeight : function() { return _height; } } } var myBat = new Batiment("test"); myBat.setPosition(10, 10); myBat.show();
Si quelqu'un aurait une idée ?Erreur*: missing } after property list
Code Source*:
setSize : function(width, height)
Par ailleurs, j'aimerais pouvoir retourner le couple width, height dans un seul et unique getter, comment puis-je faire ça proprement?
![]()
Partager