JavaScript Create objects

Source: Internet
Author: User

Method one var person = new Object ();p erson.name = "Jerry";p erson.age = 24;person.job = "Software Engineer";p erson.sayname = Fu Nction () {alert (this.name);};/ /Method Two var person = {name: ' Jerry ', Age: "", Job: "Software Engineer", Sayname:function () {alert    (this.name);    }};//method Three function Createperson (name, age, Job) {var p = new Object ();    P.name = name;    P.age = age;    P.job = job;    P.sayname = function () {alert (this.name);    }; return p;}    var person = Createperson ("Jerry", "Software Engineer");//method four function person (name, age, Job) {this.name = name;    This.age = age;    This.job = job;    This.sayname = function () {alert (this.name); };} var person = new Person ("Jerry", "Software Engineer");//method five function person () {}person.prototype.name = "Jerry"; Person.prototype.age = 24; person.prototype.job-= "Software Engineer"; Person.prototype.sayName = function () {alert (this.name);}; var person = new person ();//method six function PErson () {}person.prototype = {Constructor:person, name: "Jerry", age:24, Job: "Software Engineer", s    Ayname:function () {alert (this.name);    }};var person = new person ();//method Seven: Recommended function person (name, age, Job) {this.name = name;    This.age = age; This.job = Job;}    Person.prototype = {Constructor:person, sayname:function () {alert (this.name); }};var person = new Person ("Jerry", "Software Engineer");//method eight: Recommended function person (name, age, Job) {this.name = Nam    E    This.age = age;    This.job = job;        if (typeof this.sayname! = "function") {Person.prototype.sayName = function () {alert (this.name); }}}var person = new Person ("Jerry", "Software Engineer");

  

JavaScript Create objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.