JavaScript objects and knowledge-oriented objects

Source: Internet
Author: User

In JavaScript, objects are data that owns properties and methods, which are values associated with an object, by actions that can be performed on an object. JavaScript implements object-oriented programming in a way called prototypes. (Object-oriented is only a concept or a programming idea, it does not depend on a language exists.) )

First, create the object

1. Built-in objects: Common string, Date, Array, Boolean, Math, REGEXP

2. Custom Objects

01. Creating objects based on object objects

The Var object name =new an object (); (an object was created)

The object name. Property name = "attribute value"; (add attribute to object)

The name of the object. Method Name =function () {JavaScript statement} (Add method to object)

02. Literal value Assignment method

var object name ={Property Name 1: Property value 1, property Name 2: Property value 2, Method name: function () {JavaScript statement}} (note the attribute name and attribute value are separated by a colon, and multiple attributes are in comma--json format)

Second, the structure function

The so-called "constructor" is a normal function, but the this variable is used internally, and the new operator is used on the constructor to generate the instance, and the this variable is bound to the instance object

function     Flower (name,genera,area,use) {    this. name=name;      this. genera= genera;     this. area= area;     this. use=uses;     this. showname=showname;} function ShowName () {    alert (this. name);}

JavaScript objects and knowledge-oriented 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.