1

What would you call using multiple dot notation's to a variable?

i.e: e.target.style.textDecoration

I've tried to Google search for an answer but not sure exactly how to word the question. Plus I would like to get familiar with asking questions on stackoverflow.

  • dot notation to nested object? – depperm Mar 09 '23 at 18:00
  • In javascript it's usually called "property lookup". – Usaid Mar 09 '23 at 18:07
  • 1
    @Usaid I heard nothing about "property lookup". I think you're wrong. It's called `chaining`. – Alijvhr Mar 09 '23 at 18:13
  • @Alijvhr Just google "javascript property lookup". Chaining also seems correct. By using dot notation you are basically looking up the scope chain. – Usaid Mar 09 '23 at 18:32
  • @Usaid Actually I did google it first because i didn't hear that. There is no such thing. But "property lookup" term is generally is referred as the algorithm a language internally uses to find an array index or property of an object! – Alijvhr Mar 09 '23 at 18:48
  • @Alijvhr Yes, it's a general term. Also in my last comment, I made a mistake. It should be prototype chain not "scope" chain. – Usaid Mar 09 '23 at 18:56

1 Answers1

3

Chaining

It's called Chaining.

In JavaScript, chaining refers to the technique of calling multiple methods on an object one after the other, in a single line of code. The result of one method call is used as the object on which the next method call is made, and so on, creating a chain of method calls.

Literally you are creating chains of calls!

Chaining can make code more concise and easier to read, as it avoids the need to create temporary variables to store intermediate results.

Here is a full article about it

For your Example:

e.target.style.textDecoration

Variable e is an object and target property of that is an object too. then style is a property of e.target and so on.

Method Chaining

Method Chaining is a programming strategy that simplifies and embellishes your code. It is a mechanism of calling a method on another method of the same object.

This can be done for methods, too. If the method return type be an object.

For instance:

documet.querySelector('.divClass').click();

Also there is A new operation you can check it out. It's called Optional Chaining It checks parent not to be null. So no error will be issued if parent is null or non-object. MDN Documentation

Alijvhr
  • 1,695
  • 1
  • 3
  • 22