This article mainly introduces how to use the constructor mode and prototype mode in combination with javascript, and analyzes the usage of the javascript constructor mode and prototype mode through a simple example, for more information about how to use the constructor mode and prototype mode in javascript, see the following example. Share it with you for your reference. The details are as follows:
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.