“This is the 10th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”

Some strange internal properties and methods in Object are discussed in section 6.1.7.2 of the ECMA-262 standard. These properties and methods are implemented by the JavaScript engine, but they are abstracted from the runtime, meaning you can’t access them like normal properties and methods.

These internal properties and methods are typically represented in the ECMAScript standard as [[name]], with name representing the names of internal properties and methods. Internal properties are called internal slots, which contain values associated with the object to represent some state of the object.

Let’s look at a quick example. The [[GetPrototypeOf]] inner method is implemented by all objects and returns the prototype of that object. When reflect.getPrototype (obj) is executed, the JavaScript engine calls the [[GetPrototypeOf]] inner method and returns the value of the [[Prototype]] inner slot, The inner slot contains the prototype of its object.

Obj.__proto__ also points to the object’s prototype, which is similar to the method above.

When an internal method of an object is called, as in the example above. This object is called the “target” of the call. If target does not support internal methods, such as when we call reflect.getProtoTypeof (null), TypeError will be raised.

Object can use multiple internal slots and internal methods. The ECMAScript standard does not describe which internal violations should be implemented but it does describe the signature of the calling method. The internal methods in the table below are implemented by all objects.

Inline slots and inline modes help with the ECMAScript specification, where they are referenced to convey appropriate behavior. For example, when the [[Prototype]] keyword appears, we know that the standard is talking about internal attributes that contain the object’s Prototype.

Internal slots and internal methods help achieve consistent behavior of objects, and implementors (JavaScript engines) can provide these implementations correctly by looking at the specification. However, it does not have to follow the function signature specified by the specification. Ecmascript 6 – Are Internal slot and Internal Methods actually Implemented by JavaScript Engines? – Stack Overflow) will give you some ideas.

The ES6 standard provides a Reflect object to provide the ability to examine and modify objects. For example, the reflect. has(target, key) method checks whether the target object has a key attribute in it or in its prototype object. It is similar to the in operator, but is a function of form.

When target calls this method (has), the JavaScript engine executes the [[hasProperty]] internal method implemented by the JavaScript engine. Different JavaScript engines can implement this approach differently, but it should follow the ECMA-262 specification.

ES6 also provides a Proxy constructor, which can be used to create a Proxy object for an object. For example, let proxy = new proxy (target, handler) The proxy object provides the interface on the target object through hanlder. The Handler object contains a series of methods that can intercept methods on the original object.

Therefore, these handlers are called “traps” because they intercept operations on a target. These handler methods are similar to the Reflect method with the same name. For example, handler.has is executed when the IN operator is called on the proxy.

If the handler object does not have a specific method, as in this case, the JavaScript engine automatically executes the internal method method associated with the target of [[haPproperty]] (which is similar to reflect.has).

I know it is very difficult to understand the concept of inner slots and inner methods. But don’t worry, I’ve written about Reflect and Proxy to help you sort it all out.

Finally, the JavaScript runtime is not exposed to these internal slots, and the internal methods are limited to ECMAScript specification documents.

To further elaborate, the V8 team has written a concise article on how to read the ECMAScript specification, which also contains some information about internal slots and internal methods. I think it’s worth reading for JavaScript developers. It is also a short document, Understanding the ECMAScript Spec, Part 1 · V8, which is highly recommended.