Skip to content

[BUG] v3.3.7 of Click Analytics is throwing a ReferenceError: Cannot access xxx before initialization #2529

@MSNev

Description

@MSNev

As part of the changes in v3.3.7, this is causing a ReferenceError exception to be thrown when run in strict mode.

This is due to the following code

        let unloadHandler: IUnloadHook = onConfigChange(_config, () => {
            _clickCaptureElements =  arrMap(_config.trackElementTypes.toUpperCase().split(","), tag => strTrim(tag));
        });
        let _clickCaptureElements: string[];

The onConfigChange is run synchronously and attempts to "set" the local variable which does not yet exist.

The fix is simply to define the variable before the onConfigChange call.

Metadata

Metadata

Labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions