Home  >  Article  >  Web Front-end  >  Does javascript have objects?

Does javascript have objects?

青灯夜游
青灯夜游Original
2021-10-18 14:40:222022browse

javascript has objects. JavaScript supports three types of objects: 1. Built-in objects, which are predefined objects in the JavaScript language itself, such as String, Number, Array, etc.; 2. Browser objects; 3. Custom objects.

Does javascript have objects?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

In JavaScript, almost everything is an object. An object is a collection of related properties and methods. JavaScript supports three types of objects: built-in objects, browser objects, and custom objects.

1. JavaScript built-in objects:

refers to the predefined objects of the JavaScript language itself. It is defined in the ECMAScript standard and is provided by all browser manufacturers. Since The standards are unified, so the browser compatibility problem of these objects is not too big

String, Number, Boolean, Array, Date, RegExp, Math, Error, Object, Function, Global

2. JavaScript Window - Browser Object:

The Browser Object Model (BOM) allows JavaScript to talk to the browser.

There is no official standard for the Browser Object Model (BOM). Modern browsers have implemented (almost) the same methods and properties for JavaScript interaction, so it is often mentioned as a method and property of the BOM.

Methods and properties are often considered BOM because modern browsers have implemented (almost) the same methods and properties for JavaScript interactivity.

Window object:

All browsers support the window object. It represents the browser window.

1), the window object is the top-level object;

2), the window object has 6 major attributes, including: document, frames, history, location, navigator, screen, these 6 major attributes The properties themselves are also objects;

3), the document properties under the window object are also objects, and there are also five major properties under the document (anchors, forms, images, links, location) that are also objects.

3. JavaScript custom objects:

Through JavaScript, you can define and create your own objects.

There are many different ways to create new objects. Two are introduced below:

  • Use Object to define and create instances of objects.

  • Use object literals.

1) Using Object

In JavaScript, almost all objects are instances of the Object type, and they all inherit properties and methods from Object.prototype.

The Object constructor creates an object wrapper.

Object constructor will create an object based on the given parameters. The specific situations are as follows:

  • If the given value is null or undefined, it will be created and returned. An empty object.

  • If a basic type value is passed in, an object of its wrapping type will be constructed.

  • If the value passed in is a reference type, this value will still be returned. The variable copied by them retains the same reference address as the source object.

When called as a non-constructor, Object behaves like new Object().

Syntax format:

// 以构造函数形式来调用
new Object([value])

value can be any value.

The following examples use Object to generate Boolean objects:

// 等价于 o = new Boolean(true);
var o = new Object(true);

2) Use object literals

You can also use object literals to create objects, the syntax format is as follows:

{ name1 : value1, name2 : value2,...nameN : valueN }

actually creates name:value pairs inside curly brackets, and then separates name:value pairs with commas ,.

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of Does javascript have objects?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn