An Object is an unordered set that stores any type of objects. All other objects inherit from this Object. There are two types of Object creation: the new operator and the literal representation.
Object Section
Object Type
An Object is an unordered set that stores any type of objects. All other objects inherit from this Object.
There are two types of Object creation: the new operator and the literal representation.
1. Use the new operator to create an Object
Var obj = new Object (); // note the upper case, you can also directly write the Object ()
Note: The new Object is generated using the new Object () method, which is equivalent to the literal method obj =.
2. Create using the literal method:
Var obj = {name: 'trigger4', age: 21}; // it is best to add a semicolon
When an Object is declared using a literal, the Object () constructor (except FF) is not called)
Object. prototype Object
All constructors have a prototype attribute pointing to a prototype object.
Object.prototype.print = function(){ console.log(this)};var obj = new Object();obj.print() // Object
The instance obj directly inherits the attributes and methods of Object. prototype.
1. The object is only a special type of data. The object has attributes and methods. JavaScript is an object-oriented language, but JavaScript does not use classes. JavaScript is based on [prototype] [1] instead of class-based. 2. attribute: a variable that belongs to a specific object. Method: it is a function that can only be called by a specific object. 3. js objects are a collection of attributes and methods. A method is a function that is a member of an object. An attribute is a value or a group of values (in the form of an array or object) and a member of an object. 4. js objects are based on constructors. When using constructors to create a new object, it can be said that a new object is instantiated. Attribute is the variable inside the constructor function.
Objects instantiated using constructors:
cat = new Animal();
Javascript is an object-based language. Almost everything you encounter is an object. However, it is not a real Object-Oriented Programming (OOP) language, because its syntax does not contain class ).