Detailed introduction to js objects
a. JS objects are all associative arrays
b. inherit(); returns a new object that inherits the properties of the prototype object p
Object method :
Create (create) Set (set) Search (query) Delete (delete) Test (test) and enumerate (enumerate)
Methods to create objects:
Object literal keyword new Object.create()
in es5 var aa=Object.create({"x":0,"y":1})
Reading of attributes Retrieval and modification:
1. Through . connection Attributes cannot be changed and cannot be changed at runtime
2. Through object['xxx']; Attributes can be variables, such as object[' xx'+a]; a can be a variable, so the attribute is undefined and can be changed during operation
3. Querying for an attribute that does not exist will return undefined
4. Querying an object property, if the object does not exist, an error will be thrown. If you query the attributes of an object and prevent it from reporting an error, you can do this:
var a=b&&b.c&&b.c.d;
Deletion of attributes
1. Delete can only interrupt Open the connection between the host and the host object without operating the properties in the properties. Global object properties created through variable declarations or function declarations cannot be deleted. True is returned on success and false is returned on failure
delete a.b// a no longer has the attribute b
delete a['b']//a no longer has the attribute b
Detection of the attribute
1.in operator, hasOwnProperty(), propertyIsEnumerable()
The property name on the left side of in, and the other side is the object. If the object's own property or inherited property contains this property, it returns true, otherwise false
var a={x:1 } a.hasOwnPreperty('x');//true
PropertyIsEnumerable() is an enhanced version of hasOwnPreperty(). Only the property that is enumerable and belongs to this object will return true
2. The simplest method! ==Is it undefined
Enumeration of properties
1. All properties added to the object in the code are enumerable. In for/in we need to skip some properties
for(p in o){
if(!o.hasOwnproperty(p)) continue ;//Skip inherited properties
}
for(p in o){
if(typeof o[p]==="function") continue ;//Skip method
}
2. In There are two more functions in es5
Object.keys();//Returns an array, which consists of the enumerable own properties of the object
Object.getOwnPropertyNames(); //Return the names of all the own properties in the object
Attribute getter and setter (accessor attribute)
1.var 0={
a:1,/ /Ordinary data attributes
//Accessor attributes are functions defined in pairs
get b(){This is the function body},
set c(){This is the function body}
}
Three attributes of the object
1. Prototype attributes:
var p ={x:1};//Define a prototype object
var o=Object.create(p);Use this prototype to create an object
p.isPrototypeOf(0);// true,o inherits from p
Object.prototype.isPrototypeOf(o);//p inherits from Object.prototype
2. Class attributes
3. Extensibility Determine whether the object is extensible by passing the object into Object.esExtensible() Cannot be converted back
Object.seal() can not only set the object as non-expandable, but also set all its own properties as non-configurable
isSealed() detects the object Whether it is closed
Object.freeze() Frozen, not only unconfigurable, but also readable
Object.isFrozen() Check whether the object is frozen
Object serialization
1:JSON.stringify();//Convert to JSON string
2::JSON.parse();//Convert to object
Object method:
1.toString();
2.toLocaleString();
3.toJSON();
4:valueOf();
The above is the detailed content of Detailed introduction to js objects. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Here's how to convert a MySQL query result array into an object: Create an empty object array. Loop through the resulting array and create a new object for each row. Use a foreach loop to assign the key-value pairs of each row to the corresponding properties of the new object. Adds a new object to the object array. Close the database connection.

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

PHP functions can encapsulate data into a custom structure by returning an object using a return statement followed by an object instance. Syntax: functionget_object():object{}. This allows creating objects with custom properties and methods and processing data in the form of objects.

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

In C++, there are three points to note when a function returns an object: The life cycle of the object is managed by the caller to prevent memory leaks. Avoid dangling pointers and ensure the object remains valid after the function returns by dynamically allocating memory or returning the object itself. The compiler may optimize copy generation of the returned object to improve performance, but if the object is passed by value semantics, no copy generation is required.

In PHP, an array is an ordered sequence, and elements are accessed by index; an object is an entity with properties and methods, created through the new keyword. Array access is via index, object access is via properties/methods. Array values are passed and object references are passed.
