You do not know the JS series (36) - [[Get]] and [[Put]]

[[Get]]
Object Access there is a subtle but very important details in the realization
var myObject = {
  a: 2
}
myObject.a; // 2

myObject.a is a property access, in the realization, myObject.a on myObject actually achieved [[Get]] operation (a bit like a function call: [[Get]] ()). First look at whether the object has the same property name, if found it will return the value of this property. If none is found, by definition [[Get]] algorithm performs another very important behavior is to traverse the prototype chain that may exist. If in any case are not found, it returns the value undefined

var myObject = {
  a: 2
}
myObject.b; // undefined

 

 

[[Put]]
You might think that assigns them an object triggers [[Put]] to set or create the property, but in fact is not entirely the case. [[Put]] is triggered, the actual behavior depends on many factors, including the existence of this attribute object. If the property already exists
1 , whether the property is access descriptor, and if there is a setter is called setter
 2, whether the attribute data descriptor writable is false , it will call fails, will throw an exception strict mode
 3, if not, the value is set for the value of the property

If this attribute is not present in the object, [[Put]] operation is more complicated

 

Guess you like

Origin www.cnblogs.com/wzndkj/p/12563707.html