Skip to content Skip to sidebar Skip to footer

Javascript Invalid Left-hand Side In Assignment Expression When Renaming

I have some code which is giving me the following error when I rename a class name. This gives no error: this.container = document.createElement('ul'), But when I rename the conta

Solution 1:

use _ instead of -, so this.tt_container, not this.tt-container

Solution 2:

From MDN,

An object property name can be any valid JavaScript string, or anything that can be converted to a string, including the empty string. However, any property name that is not a valid JavaScript identifier (for example, a property name that has a space or a hyphen, or that starts with a number) can only be accessed using the square bracket notation.

In your case - is not a valid JavaScript identifier. To use -, Use Bracket Notation

this["tt-container"] = document.createElement("ul"),

Post a Comment for "Javascript Invalid Left-hand Side In Assignment Expression When Renaming"