Skip to content

MutationObserver article uses non-existent Prism.highlightElem instead of Prism.highlightElement #3979

Description

@Violet-Bora-Lee

Article

https://javascript.info/mutation-observer (2-ui/99-ui-misc/01-mutation-observer/article.md)

Problem

The prose and inline code examples in the "Usage for architecture" section refer to Prism.highlightElem (6 occurrences), but this method does not exist in the Prism.js API. The correct name is Prism.highlightElement, which the demo code later in the same article already uses:

// inline example (incorrect)
document.querySelectorAll('pre[class*="language"]').forEach(Prism.highlightElem);

// demo code in the same article (correct)
Prism.highlightElement(node);

Readers who copy the inline examples get a TypeError, and the inconsistency within one article is confusing (this was noticed during a review of the Korean translation: javascript-tutorial/ko.javascript.info#1900).

A related nit in the same lines: passing the method reference directly to forEach forwards (element, index, array) into the highlightElement(element, async, callback) signature, so the index ends up as the async argument. Wrapping it in an arrow function that passes only the element avoids that.

I'll send a PR fixing both.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions