Javascript combines the constructor mode and prototype mode instance.
This example describes how to use the constructor mode and the prototype mode in javascript. Share it with you for your reference. The details are as follows:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Function testPrototype2 (){ Function Person3 (name, age, job ){ This. name = name; This. age = age; This. job = job; This. friends = ["shelb", "court"]; } Person3.prototype = { Constructor: Person3, SayName: function (){ Alert (this. name ); } } Var person1 = new Person3 ("jack", 10, "it "); Var person2 = new Person3 ("karry", 1, "woker "); Person1.friends. push ("tom "); Console.info (person1.friends ); Console.info (person2.friends ); Console.info (person1.friends = person2.friends ); Console.info (person1.sayName = person2.sayName ); } |
I hope this article will help you design javascript programs.