Speaking of reflection, in fact many languages such as Java and. NET has the mechanism of reflection, see this tall noun, you will certainly think this is what thing. Is reflection something that is not a mapping of something?
No.
We can interpret the reflection as plain as: when you are dealing with an unknown object (you don't even know a property or API of the object), pry into its internal structure, get its internal properties and methods, and that's the reflection mechanism.
OK, how do we spy on the object's internal structure?
For (var prop in obj) {console.log (prop); or the other statement}
What is the purpose of getting each property or method, we are going to spy on an object, to use its things, what we do is meaningful.
For (var prop in obj) {if (typeof obj[prop] = = = ' function ') {obj[p] (); Methods to implement}else{Console.log (Obj[p]); property on Output}}
So that we can use the property or the method inside, so that the reflection mechanism appears to be meaningful.
Example: Assigning a property of an object obj1 to a obj2, requiring that the more than obj1 attribute in the Obj2 not be washed away, and if there are duplicate attributes, it is overwritten.
For (Var prop in obj1) {
Obj2[prop] = Obj1[prop];
}
Console.log (OBJ2); This allows the OBJ2 to save its own attributes to the latest values and to increase the new properties of Obj1.
This article is from the "8129266" blog, please be sure to keep this source http://8139266.blog.51cto.com/8129266/1835762
Javascript------Reflection Mechanism