Use two functions in the same Javascript

Asked

Viewed 110 times

0

I will try to be as clear as possible so that you can understand me and help, I have the javascript next.

function labelthumbs(e) {
document.write('<ul id="test">');
}

It uses the function labelthumbs and I would like to add another function labelthumbs2 in that same javascript without having to duplicate and create 2 javascript with different functions.

Instead of:

function labelthumbs(e) {
document.write('<ul id="teste">');
}

function labelthumbs2(e) {
document.write('<ul id="teste">');
}

I’d like something that looks like this and that works:

function labelthumbs(e)
function labelthumbs2(e)
{
document.write('<ul id="teste">');
}
  • 1

    There is not much feeling, why not create a single function that does both actions? I just don’t understand why you are using the variable and which is usually used for events and by your example both functions do exactly the same thing.

  • Explain your need better. The way you explained it is not making sense.

  • It didn’t make sense to me. You could call the function more than once, or put duplicate content <ul><ul>. I think in order to help you we need to understand what your goal is with the function.

  • Ideal would be to explain the need to do this.

2 answers

1

If what you need is to keep the same code for both of you, you can do it like this:

function labelthumbs(e){
    document.write('<ul id="teste">');
}
function labelthumbs2(e){
    labelthumbs(e);
}

Thus, when editing the labelthumbs the response of the other changes tb

0

From what I understand intends to create two identical functions by making only a "statement".

A possible solution would be:

var labelthumbs = labelthumbs2 = function(e){ document.write('<ul id="teste">'); }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.