Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

99
Vistas
How to generate random unique static id in javascript

I am prototyping a project that requires a unique id for each functions. here is an example.

function Example(name, uuid) {
    ...
}

function start() {
    Example("Jeeva", 1)
    if (...) {
        Example("Peter", 2)
    }
    Example("June", 3)
}

As you can see the start function may called multiple times. but I want the id to be same. the id doesn't have to be a number it could be anything but has to unique to that function call.

I tried to store the ids in a list outside the start function and adding the id on first call and shifting them on other calls. But the issues is inside the if statement the function might not be executed. so after the first call if the condition changes then Example function will be called and shifting the id will return fails.

Can anyone point me in the right direction or is it impossible in this case?

Edit

OK, let me tell you why do I want this functionality. Simply put I am trying jetpack compose. If you don't know how jetpack compose works. It's a declarative UI framework. It updates (recompose) it's UI on state changes.

I am not doing this project for production, just to learn (out of curiosity).

here is an example that I am testing right now.

import { Compose } from "../src/core/Compose"
import { Text } from "../src/composable/Text"

const App = scope => {
    let text = scope.stateOf("hello", 1)

    Text({ 
        text: text.value
    }, scope, 1)

    if (text.value === "hello, world") {
        Text({ text: "Hi" }, scope, 2)
    }

    if (text.value == "hello") {
        setTimeout(() => text.value = "hello, world" , 2000)
    }
}

new Compose("#app").mount(App)

As you can see I am passing unique numbers at the end of each composables and state. this allows me to find them on recomposition.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda