Is JavaScript Reflective Mechanism What?

  node.js, question

JavaScriptReflectionMechanism, according to Baidu’s results, JavaScript reflection results are not the same, what is reflection?
Some people say that languages such as dynamic language (php,javascript) are not reflective.
It is best to have examples. Thank you all.

Don’t reflect for reflection.

The subject may reflect for reflection. (js reflections can be seen everywhere, and you may use them frequently.)

Reflective concepts are stronger in languages like java and go. Because they are all static languages. Lack of many dynamic characteristics. They can only reflect through a lot of api. That is why there is the concept of relatively strong reflection.

Js is an object-oriented functional language based on prototype inheritance. Reflection is everywhere. (When a concept is everywhere, then setting a concept gradually fades out. )

Js reflex is the simplest example.

How do you communicate with an object if you don’t know its internal structure (you don’t even know an attribute or api of the object)? At this time, it is necessary to obtain its internal structure through a mechanism. This mechanism is called reflection. To put it bluntly, the way to spy on the internal structure of an object is called reflection.

Example 1:

for (var prop in window) {
 console.log(prop);
 bracket
 
 // Object.keys(window).forEach(console.log);  Same result

Maybe you will ask? This comparison traverses the window object? What’s strange? If you take a closer look at this, you are looking at the internal structure of the window object. In other words, this is reflection. (window’s methods and properties are basically printed, except in some cases when enumerable:true).

Once you get the internal structure, you need to call, that is, communicate.

Window['resizeTo'](100, 200) Yes, that's as simple as that.  The reason for being so cheap is that js is a functional programming language, and functions attach importance to first-class fame in js.  Functions can be used as variables or objects.
 
 //(Window ['Resizeto']). Apply (Window, [100,200]) is equivalent to the above effect.

Js is a language with strong performance ability, which means that the code can be read well. While writing can do more with less code. Google has spent a lot of energy on v8 over the years and its performance is getting stronger and stronger. But js also has many problems. Let’s not talk about it here.