mirror of
https://github.com/bendtherules/blog-hashnode-backup.git
synced 2026-08-18 13:42:04 +00:00
update post: What is this inside foo.bar()?
This commit is contained in:
@@ -71,24 +71,22 @@ TLDR - If you would like to see me actually go through the spec, this video migh
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Link - 1. https://tc39.es/ecma262/#sec-evaluatecall, 2. https://tc39.es/ecma262/#sec-ispropertyreference
|
|
||||||
|
|
||||||
### PropertyReference
|
### PropertyReference
|
||||||
|
|
||||||
This `foo.bar` structure is defined in the spec as a [PropertyReference](https://tc39.es/ecma262/#sec-ispropertyreference).
|
This `foo.bar` structure is defined in the spec as a [PropertyReference](https://tc39.es/ecma262/#sec-ispropertyreference).
|
||||||
Think of PropertyReference as anything that is valid as the left side of an assignment expression, if you were assigning to the property of a object or primitive.
|
If you were assigning a value to the property of a object or primitive, anything that is valid as the Left Hand side of the assignment expression is a PropertyReference.
|
||||||
|
|
||||||
PropertyReference = Reference + base is object or primitive
|
So, PropertyReference = Reference + base is object or primitive
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Some examples of valid and invalid PropertyReference 👇
|
Some examples of valid and invalid PropertyReference might make it more clear - 👇
|
||||||
|
|
||||||
%[https://gist.github.com/bendtherules/3467664a9c567617342b73c3681c1dc7]
|
%[https://gist.github.com/bendtherules/3467664a9c567617342b73c3681c1dc7]
|
||||||
|
|
||||||
### Steps
|
### Steps
|
||||||
1. If it is a PropertyReference, then set `thisValue` to base of the PropertyReference (i.e. `foo` in `foo.bar`).
|
1. If it is a PropertyReference, then set `thisValue` to base of the PropertyReference (i.e. `foo` in `foo.bar`).
|
||||||
2. Or else, take thisValue from surrounding Environment Record.
|
2. Or else, thisValue is `undefined`.
|
||||||
|
|
||||||
The obtained `thisValue` is forwarded to the abstract operation [Call](https://tc39.es/ecma262/#sec-call), which in turn verifies that the resolved value of `foo.bar` is a function and then calls the internal method [function.[[Call]]](https://tc39.es/ecma262/#sec-built-in-function-objects-call-thisargument-argumentslist) with the same thisValue.
|
The obtained `thisValue` is forwarded to the abstract operation [Call](https://tc39.es/ecma262/#sec-call), which in turn verifies that the resolved value of `foo.bar` is a function and then calls the internal method [function.[[Call]]](https://tc39.es/ecma262/#sec-built-in-function-objects-call-thisargument-argumentslist) with the same thisValue.
|
||||||
This [[call]] interface is very similar to the `function.call` public interface and can be approximated with that. One small diff. we noted earlier is that [[call]] changes `this` value from undefined to global object in non-strict mode.
|
This [[call]] interface is very similar to the `function.call` public interface and can be approximated with that. One small diff. we noted earlier is that [[call]] changes `this` value from undefined to global object in non-strict mode.
|
||||||
|
|||||||
Reference in New Issue
Block a user