How do you describe an element in terms of ES5 (2)?

In terms of language, what do I need to return when I take an element from the DOM as such:

var obj = document.getElementById('foo'); 

It has properties, so I thought that maybe it could be an object literal. Using type checks, I determined that this is not an object literal, nor is it an array literal.

I know what it is used for and how to use it, just not what it is, technically speaking the language.

I checked this through this test, which I call the test for abstract object .

 obj === Object(obj); 

which it returns false.

I know that I can identify node elements as such

 obj.nodeType === 1 

but still it doesn’t tell me what it is, in terms of language (ES5). What is an element expressed in terms of language?

Explanation

I mean a language based on grammar, JavaScript, the Good Part, chapter 2, This grammar only knows how to deal with language components, arrays, objects, etc.

+4
source share
2 answers

In terms of the ECMAScript DOM Elements specification, are β€œ host objects ” provided by the browser host environment (note below):

ECMAScript, as defined here, is not intended for self-calculation; indeed, there are no provisions in this specification for inputting external data or for outputting calculated results. Instead, it is expected that the computing environment of the ECMAScript program will provide not only the objects and other objects described in this specification, but also specific host objects that are specific to the environment, the description and behavior of which are outside the scope of this specification , except that they can provide certain properties that can be accessed, and some functions that can be called from ECMAScript.

The specific properties of DOM elements are determined by the interfaces outlined in the W3C DOM specification , not by the ECMAScript specification (although the ECMAScript spec allows them to exist by providing object objects provided by the environment).

Addendum:

You have added some clarification that your confusion stems from the fact that JavaScript uses grammar. I find it difficult to understand why this is causing confusion for you, but I will try to figure it out.

JavaScript grammar is lexical, i.e. deals with written code. This written code is parsed (using grammar), and the parser identifies certain expressions in the code. These expressions correspond to software operations in the runtime.

The grammar used to refer to the host object is identical to the grammar used to refer to the native object. In fact, the host object is an object. The only difference is that the host object indicates the behavior of its internal methods , for example [[Get]] (used to access properties).

+3
source

Element not defined in ES5 terms. This is part of the DOM API.

Here is his definition

The Element interface is an element in an HTML or XML document.

The language should not implement the ES5 specification to implement the DOM API, moreover, the ES5 implementation may be valid and not run Element . For example, NodeJS runs server-side JavaScript and does not implement Element.

+5
source

Source: https://habr.com/ru/post/1493689/


All Articles