Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
javascript Dynamic function arguments

how to setup to use function arguments dynamically, i have tried many method and it doesn't work properly. Hope someone can help me, Thank you very much.

Function:

function initDropdown(type, placement, trigger, strategy, functions) {
    tippy('[data-cg-toggle="' + type + '"]', {
        zIndex: 99999,
        interactive: true,
        placement: placement,
        allowHTML: true,
        trigger: trigger,
        popperOptions: {
            strategy: strategy,
        },
        functions
    });
}

Init Functions

initDropdown('dropdown', 'bottom-end', 'click', 'fixed', {
    content(reference) {
        return content;
    },
    onShown(instance) {
        $($(instance)[0].reference).addClass('dropdown-toggled');
    },
    onHidden(instance) {
        $($(instance)[0].reference).removeClass('dropdown-toggled');
    }
});

initDropdown('dropdown', 'bottom-end', 'click', 'fixed', {
    onShown(instance) {
        var content = $($(instance)[0].reference).parent().children('.dropdown-menu')[0].innerHTML;
        $($(instance)[0].reference).addClass('dropdown-toggled');
        instance.setContent(content);
    },
    onHidden(instance) {
        $($(instance)[0].reference).removeClass('dropdown-toggled');
    },
});
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You Can Use Javascript Object In This Case

While Declaring Your Function:

function myFunc (options = {}) {
  if(typeof options === 'object') {
    let a = options.type;
    console.log(a)
    return true
  }
  throw new Error("Oops.. MyFunc Accepts only Objects!")
}

And While Calling It:

myFunc({
  type: 'number',
  etc: '1', // you can add as many values as you want and access it in the function.
})

You Can Learn More About It Here

about 4 years ago · Juan Pablo Isaza Report

0

You can use

Object.assign({}, { ...options... }, functions)

or, as tagged jquery

$.extend({}, { ...options... }, functions)

Example:

function initDropdown(type, placement, trigger, strategy, functions) {
  tippy('[data-cg-toggle="' + type + '"]',
    Object.assign({}, {
        zIndex: 99999,
        interactive: true,
        placement: placement,
        allowHTML: true,
        trigger: trigger,
        popperOptions: {
          strategy: strategy,
        }
      },
      functions
    });
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!