The examples in this article describe the methods used by JavaScript combinations to use constructor patterns and prototype patterns. Share to everyone for your reference. Specifically 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 with your JavaScript programming.