JavaScript notes and Summary (1-6) JavaScript Object-oriented

Source: Internet
Author: User

In JavaScript, there are objects, there are no classes (but there are constructors).

In JavaScript, objects exist that are not dependent on classes and can be generated directly.

{Key:value, Key:value} objects of this format become JSON -formatted objects.

Cases:

<script>    var obj = {};     var obj2 = {key:1};     var obj3 = {        key:1,         key2:function() {            alert (' Hello World ');}    }     Console.log (obj, obj2, obj3);        Obj3.key2 (); </script>

Output:

Simultaneous popup: Hello World

The properties (or methods) of the JS object can also be arbitrarily added and deleted.

① increasing the properties of an object

<script>    var obj = {};     var obj2 = {key:1};     var obj3 = {        key:1,         key2:function() {            alert (' Hello World ');}    }     Console.log (OBJ3);         = 2;    Console.log (OBJ3); </script>

Output:

② deleting an object's properties (or methods)

<script>    var obj = {};     var obj2 = {key:1};     var obj3 = {        key:1,         key2:function() {            alert (' Hello World ');}    }    Console.log (OBJ3);     // increase the properties        of an object Obj3.key3 = 2;    Console.log (OBJ3);     // delete an object's properties    Delete Obj3.key2;    Console.log (OBJ3); </script>

Output:

Summary

The object in JS is "a set of attributes and values", which can be arbitrarily increased or decreased, and the methods and properties need not be differentiated.

JavaScript notes and Summary (1-6) JavaScript Object-oriented

Related Article

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.