Как метод связывания вроде реагирует. js в vanillaJS - PullRequest
0 голосов
/ 12 марта 2020

У меня JavaScript class, и я хочу вызвать метод из строкового литерала:

    export default class Popup {
        constructor(props){
            this.state = { text: "Text" }
//            this.show = this.show.bind(this);
            this._id = this.constructor.name;      
            document.classes[this._id] = this;
        }

        show(){
            alert("Hi!");
        }

        render(){
            return `<div onclick="document.classes[${this._id}].show()">${this.state.text}</div>`;
        }
    }

Это index.html:

<script type="module">
     document.classes = {};
     import Popup from "./utils/popup.js";
     var popup = new Popup({});
     document.querySelector('#popup').innerHTML = popup.render();
</script>
<div id="popup"></div>

Но ничего не происходит или Uncaught ReferenceError: Popup is not defined. Как я могу заставить этот метод вызывать? Я хочу сделать как в реакции только на VanillaJS.

...