Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to create objects in html

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "what are the ways to create objects in html", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what are the ways to create objects in html" this article.

Several ways to create objects / / simply create objects var person = new Object (); person.name = "nicholas"; person.age = 23 person.job = "IT"; person.sayName = function () {alert (this.name);}; person.sayName (); / / literal var person = {name: "nicholas", age: 23 name: "IT", sayName: function () {alert (this.name);}; person.sayName () / nicholas// factory mode function createPerson (name, age,job) {var o = new Object;o.name = name;o.age = age;o.job = function () {alert (this.name);}; return o;} person1 = createPerson ("nicholas", 20, "IT"); person1.sayName (); person2 = createPerson ("blue", 23, "HR"); person2.sayName (); / / Constructor mode function Person (name, age,job) {this.name = name This.age = age;this.job = job;this.sayName = sayName;} function sayName () {alert (this.name);} var person1 = new Person ("nicholas", 20, "IT"); person1.sayName (); var person2 = new Person ("gred", 22, "HR"); person2.sayName (); / / prototype mode function Person () {}; Person.prototype.name = "nicholas"; Person.prototype.age = 20tPerson.prototype.job = "IT" Person.prototype.sayName = function () {alert (this.name);}; var person1 = new Person () person1.sayName (); var person2 = new Person (); person2.sayName (); alert (person1.sayName = = person2.sayName); / / prototype mode-simplified function Person () {}; Person.prototype = {name: "nicholas", age: 20 person2.sayName: "IT", sayName: function () {alert (this.name);}; var person1 = new Person (); person1.sayName () Var person2 = new Person (); person2.sayName (); / / combine construction pattern and prototype pattern function Person (name, age, job) {this.name = name;this.age = age;this.job = job;this.friends = ["xiaoming", "daming"];} Person.prototype = {constructor: Person,sayName: function () {alert (this.name);}} var person1 = new Person ("nicholas", 20, "IT"); person1.sayName () / / nicholasperson1.friends.push ("Van"); alert (person1.friends); / / xiaoming,daming,Vanvar person2 = new Person ("blue", 22, "HR"); person2.sayName (); / / bluealert (person2.friends); / / xiaoming,daming// dynamic prototype pattern function Person (name, age, job) {this.name = name;this.age = age;this.job = job;if (typeof this.sayName! = "function") {Person.prototype.sayName = function () {alert (this.name) };} var friends = new Person ("nicholas", 20, "IT"); friends.sayName (); / / parasitic constructor model function Person (name, age, job) {var o = new Object (); o.name = name;o.age = age;o.job = job;o.sayName = function () {alert (this.name);}; return o;} var person1 = new Person ("nicholas", 20, "IT"); person1.sayName () / / secure mode function Person (name, age, job) {var o = new Object (); o.name = name;o.sayName = function () {alert (name);}; return O;} var person1 = new Person ("nicholas", 20, "IT"); person1.sayName (); these are all the contents of the article "what are the ways to create objects in html?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report