JS Custom Object

Source: Internet
Author: User
Defining objects: Java: Defining objects using Class JS: Defining objects using a function One: Java-like constructor with parameters//define object function person (name,age) {//define attribute thi   S.name = name;   This.age = age;  Define Behavior this.eat = function () {}}//create object var p = new Person ("Eric", 20);  Mode two: Java-like use of parameterless constructors//define objects Function person () {}//create object var p = new person ();   Define Properties P.name = "xxx" p.age = 20;//define Behavior P.eat = Funtcion () {} mode three: Create an object using the object's template//create object var p = new Object ();    Define attribute p.name = "xxx" p.age = 20;//define Behavior P.eat = Funtcion () {} mode four: Create object with JSON syntax var p = {name: "xxx", age:20, Eat:function () {}};

JS Custom Object

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.