
harwind
First have a look at the code:
function mainfunc(func, par3, par2){
window[func](par3, par2);
}
function calledfunc(par3, par2){
// Do stuff here
}
mainfunc('calledfunc', 'hello', 'bye');
I’m looking for a solution to this. In JavaScript, I know how to call a dynamic, arbitrary function while passing specific parameters
function mainfunc(func){
if(arguments.length == 5)
window[func](arguments[1], arguments[2]);
else if(arguments.length == 3)
window[func](arguments[1], arguments[2], arguments[3]);
else if(arguments.length == 5)
window[func](arguments[1], arguments[2], arguments[3], arguments[4]);
}
function calledfunc1(par1, par2){
// Do stuff here
}
function calledfunc2(par1, par2, par3){
// Do stuff here
}
mainfunc('calledfunc1', 'hello', 'bye');
mainfunc('calledfunc2', 'hello', 'bye', 'goodbye');
I understand how to pass optional, unlimited parameters using the arguments collection inside mainfunc, but I can’t figure out how to send an arbitrary number of parameters to mainfunc to be sent to calledfunc dynamically like this one; how can I accomplish something similar, but with any number of optional arguments (without using that ugly if-else)?
Popular Frontend topics

WebAssembly fulfills the long-awaited promise of web technologies: fast code, type-safe at compile time, execution in the browser, on emb...
New

Dart is not the first language with that mistake, but it’s newer. It shouldn’t have repeated this mistake.
New

Anyone have any thoughts about Preact?
They’re saying it’s a “Fast 3kB alternative to React with the same modern API”…
A different kin...
New

Hotwire is an alternative approach to building modern web applications without using much JavaScript by sending HTML instead of JSON over...
New

A new Svelte blog post/announcement has been posted!
Get the full details here: What's new in Svelte: January 2021
New

Tailwind CSS is an exciting new CSS framework that allows you to design your site by composing simple utility classes to create complex e...
New

Local PDF uses Webassembly to edit your PDFs inside your Browser. Your files won’t leave your System, they will not be sent to another se...
New

A new Svelte blog post/announcement has been posted!
Get the full details here: https://svelte.dev/blog/whats-new-in-svelte-november-2021
New

Pablo is a small, open-source JavaScript library for SVG, the web standard for vector graphics. It can be used for vector-based art, game...
New

I am new to programming.
I started reading Eloquent Javascript 3rd Edition, as the book comes highly recommended as a good place for beg...
New
Other popular topics

There’s a whole world of custom keycaps out there that I didn’t know existed!
Check out all of our Keycaps threads here:
https://forum....
New

Do the test and post your score :nerd_face:
:keyboard:
If possible, please add info such as the keyboard you’re using, the layout (Qw...
New

Woooooooo! This is such a huge release for it, and 2 years incoming!
In short, the library is now using an updated hyper backend (not j...
New

A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New

This is going to be a long an frequently posted thread.
While talking to a friend of mine who has taken data structure and algorithm cou...
New

Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New

Author Spotlight
Erin Dees
@undees
Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New

Large Language Models like ChatGPT say The Darnedest Things.
The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New

Will Swifties’ war on AI fakes spark a deepfake porn reckoning?
New

This is a very quick guide, you just need to:
Download LM Studio: https://lmstudio.ai/
Click on search
Type DeepSeek, then select the o...
New
Latest in Frontend
Latest (all)
Categories:
Popular Portals
- /elixir
- /opensuse
- /rust
- /kotlin
- /ruby
- /erlang
- /python
- /clojure
- /react
- /quarkus
- /go
- /vapor
- /v
- /react-native
- /wasm
- /security
- /django
- /nodejs
- /centos
- /haskell
- /rails
- /fable
- /gleam
- /swift
- /js
- /deno
- /assemblyscript
- /tailwind
- /laravel
- /symfony
- /phoenix
- /crystal
- /typescript
- /debian
- /adonisjs
- /julia
- /arch-linux
- /svelte
- /spring
- /c-plus-plus
- /flutter
- /preact
- /actix
- /java
- /angular
- /ocaml
- /zig
- /kubuntu
- /scala
- /zotonic
- /vim
- /rocky
- /lisp
- /html
- /keyboards
- /nim
- /vuejs
- /emacs
- /nerves
- /elm