Home >Web Front-end >Front-end Q&A >What are the elements of objects in javascript

What are the elements of objects in javascript

青灯夜游
青灯夜游Original
2021-10-26 18:13:283046browse

There are two elements of objects in JavaScript, namely: 1. Attributes, which are a set of data used to describe the characteristics of the object, that is, several variables; 2. Methods, which are used to operate the characteristics of the object. Several actions, that is, several functions.

What are the elements of objects in javascript

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

JavaScript supports three types of objects: built-in objects (native objects), browser objects, and custom objects. The following article will introduce it to you, I hope it will be helpful to you.

The object contains two elements:

1. A set of data used to describe the characteristics of the object, that is, a number of variables, usually called attributes.

2. Several actions used to manipulate the characteristics of an object, that is, several functions, usually called methods.

Object types of JavaScript

1. Built-in objects (native objects):

refers to the predefined objects of the JavaScript language itself, defined in the ECMAScript standard , all browser manufacturers provide specific implementations. Due to the unification of standards, the browser compatibility problem of these objects is not too big

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

2. Browser (window) object:

The Window object represents a browser window or a frame. In client-side JavaScript, the Window object is a global object and all expressions are evaluated in the current environment.

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.

Note:

All browsers support the window object. It represents the browser window. All global JavaScript objects, functions, and variables automatically become members of the window object.

  • Global variables are properties of the window object.

  • Global functions are methods of the window object.

  • Even the document object (of HTML DOM) is also a window object attribute: window.document.getElementById("header");

Equivalent to: document.getElementById("header");

3. Custom object:

refers to the object created by the user. Compatibility issues need to be paid attention to by the writer

There are 3 types of custom objects to create:

1), object direct quantity; a mapping table composed of name/value pairs. The name and value are separated by colons, and the name/value pairs are separated by colons. Comma separated var obj1 = {};

var obj2 = {x:0,y:0};
var obj3 = {name:‘Mary’,age:18}

2), new Object(); Create system object, create universal object, create custom object (custom constructor) var obj1 = new Array;

var obj2 = new Date();

3), function object template

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of What are the elements of objects in javascript. 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