Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293850

Prefer to replace some of typeof obj !== 'undefined' with optional chaining possibly

$
0
0

Problem/Motivation

Some of JavaScript checks object existence with typeof obj !== 'undefined' and checks property existence in the object. For example, it checks drupalTranslations and its property exsitence with below code in the /misc/drupal.js.

if (
  typeof drupalTranslations !== 'undefined'&&
  drupalTranslations.strings &&
  drupalTranslations.strings[options.context] &&
  drupalTranslations.strings[options.context][str]
)

This code is redundant for current JavaScript because using optional chaining operator can makes code more shorter like below.

if (drupalTranslations?.strings?.[options.context]?.[str])

Proposed resolution

Use optional chaining operator.

Remaining tasks

User interface changes

No.

API changes

No.

Data model changes

No.

Release notes snippet


Viewing all articles
Browse latest Browse all 293850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>