Create a class Person, which contains the following properties: name (name), age (age), friends (friends array), greeting (sayhi method, output greetings, such as: "Hello!"), make friends (addFriend method, add a value to friends), and then create two instances of this class: "Xiao Zhang",22,["Xiao Li","Xiao Wang "]," Hallo! "," James "," James "," James ", 24, [" Ann "," Billy "]," Hallo! "," Xiao Zhang "
Funktionsperson (Props) {this.name = props.name || 'Anonymous'; this.age = props.age || 20; this.friends = props.friends || 'none';} person.Prototype.sayhi = function () {console.log ("Hallo!"+this.name);} Person.Prototype.addfriend = function (newf) {this.friends.pushs.push (newf); conhole {});} var xiaozhang = createPerson ({name: 'xiaozhang', Alter: 22, Freunde: ["xiao li", "xiao wang"]}); xiaozhang.sayhi (); // Hallo! Xiao Zhang Xiaozhang.addfriend ('James'); // ["Xiao li", "Xiao Wang", "James"]Der obige Artikel ist ein einfaches Beispiel für das Erstellen eines personenähnlichen Inhalts, den der Editor mit Ihnen teilt. Ich hoffe, Sie können Ihnen eine Referenz geben und ich hoffe, Sie können wulin.com mehr unterstützen.