# ECMAScript proposal: Path traversal access to object parent properties (implementation). #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ECMAScript proposal: Path traversal access to object parent properties (implementation).
Motivation
All JavaScript's objects can't remember their own parent objects. Here is one solution to this problem.
I was inspired by the bstuff's
idea and wrote a small implementation
(specially for HolyJS Piter 2019).
High-level API
First you need to create some objects like:
And after that you can access any properties of the parent object using the arrays syntax:
How it works?
Assembly
Gulp was used as an assembly tool, as it is simple and easy to use.
You can look at the configuration in the
gulpfile.js
.Plugin
In order to add objects "memory" about their parent objects, I wrote a plugin that parsed javascript code
and wrapped all objects by some functions. You can see the plugin implementation in the
src/plugin/objectBindingPlugin.js
.Parsing
For parsing code was selected the package falafel.
How I parsed code you can see in
src/plugin/parse.js
.Wrapping
Your simple javascript code:
After building your code we will see the following in the bundle file:
Function
createObject
returns modified object in which each object remembers its parent(implementation:
src/plugin/service/createObject.js
).Function
getFromObject
returns requested property from an object(implementation:
src/plugin/service/getFromObject.js
).FAQ
npm i && npm run start
.src/data
and either create a new javascript file or modify existing files.
time, it became very interesting for me to implement something like this.
only to demonstrate the bstuff's idea in action :)