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