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

123
Vistas
Javascript new function without assigning it to a var

Is there a risk in declaring and calling a function without assigning it to a var ?

Normaly, I put my javascript this way:

 $(document).ready(function (ev) {

        var myFunc =  function () { 
            init();
    
            function init() {
                initEvents();
            };
    
            function initEvents() {
                ...
            };
    
        }();

But since the var is never used, and could conflict with another one in the global namespace, I am thinking of doing this instead:

  $(document).ready(function (ev) {

        new function () { 
            init();
    
            function init() {
                initEvents();
            };
    
            function initEvents() {
                ...
            };
    
        }();

Seems to work, but any danger ?

Based on the comments received, I think the solution would be to do this instead:

$(document).ready(function (ev) {
    
                init();
        
                function init() {
                    initEvents();
                };
        
                function initEvents() {
                    ...
                };
});
   
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