0

I recently got a library in Javascript and I have some code which have the following format:

file: abc1.js

export default {
    props: { /*some lines*/ }
    data() {
        return {
            field1: 'value1',
            field2: 'value2'
        }
    }
    computed: { /*some lines*/ }
    config() {
        /* some lines /*
        return {
            'abc.abc1' : function(var1) {
                // How to access these lines?
                // some code1
                // some code2
            }
            'def.def1' : function(var2) {
                // some code3
                // some code4
            }
        }
    }
}

And I would like to make a call from here:

<html>
    <body>
        <a href='#' onclick='call-to-function-abc.abc1()' /> // How?? 
    </body>
</html>

to the piece of code where abc.abc1 is. How can I do that?

Joe Almore
  • 4,036
  • 9
  • 52
  • 77
  • 1
    Inline event handlers like `onclick` are [not recommended](/q/11737873/4642212). They are an [obsolete, hard-to-maintain and unintuitive](/a/43459991/4642212) way of registering events. Always [use `addEventListener`](//developer.mozilla.org/docs/Learn/JavaScript/Building_blocks/Events#inline_event_handlers_%E2%80%94_dont_use_these) instead. What exactly is the problem with using the exported object? Have you read the documentation? [Modules](//developer.mozilla.org/docs/Web/JavaScript/Guide/Modules). What do you mean by _“How to access these lines?”_? Do you want to call the method? – Sebastian Simon Nov 25 '21 at 17:09
  • @SebastianSimon `Do you want to call the method?` Yes. Please, just focus on a call from an external file, regardless of whether it comes from. – Joe Almore Nov 25 '21 at 17:19
  • Can you clarify whether this is vuejs? – danh Nov 25 '21 at 17:42
  • @danh Whether it is using `Vue` or not is irrelevant. Somewhere else there may be a `Vuw` component, but I do not plan to use it with `Vue`, I just need to execute this code from plain `Javascript` (if possible, of course). In case not, please, you may recommend another approach to modify the code above to make it accesible. – Joe Almore Nov 25 '21 at 17:54
  • Okay, so can you call config()? Then it's `config()["abc.abc1"](someParameter)` – danh Nov 25 '21 at 18:02

0 Answers0