// Méthode 1 Objet Quantité directe
var obj1 = {v1: "", get_v1: function () {return this.v1; }, set_v1: fonction (v) {this.v1 = v; }};// Méthode 2 Définir l'objet de fonction
var obj = fonction () {var v1 = ""; this.get_v1 = function () {return this.v1; }; this.set_v1 = fonction (v) {this.v1 = v; }};// Méthode 3 Prototype Héritage
var obj3 = new function (); obj3.prototype = {v1: "", get_v1: function () {return this.v1; }, set_v1: fonction (v) {this.v1 = v; }};// Méthode 4 Mode d'usine
fonction loadoBj () {var tmp = new object (); tmp.v1 = ""; tmp.get_v1 = fonction () {return tmp.v1; }; tmp.set_v1 = fonction (v) {tmp.v1 = v; }; return tmp;} obj1.set_v1 ('hello1'); alert (obj1.get_v1 ()); var obj2 = new obj (); obj2.set_v1 ('hello2'); alert (obj2.get_v1 ()); var obj3 = nouveau obj (); obj3 obj4 = loadoBj (); obj4.set_v1 ('hello4'); alert (obj4.get_v1 ()); alert (obj1); alert (obj2); alert (obj3); alert (obj4);L'article ci-dessus discute brièvement de plusieurs méthodes de définition de classe JS couramment utilisées. C'est tout le contenu que je partage avec vous. J'espère que vous pourrez vous faire référence et j'espère que vous pourrez soutenir Wulin.com plus.