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

246
Vistas
How does function invocation work in JavaScript as an value to part of an object?

I'm working with datatables.js library. The contents of the code isn't what I'm trying to understand, but how functions work as arguments/parameters. Why doesn't the last version work, whereas the first two do? I understand that the first two are essentially the same thing, but what about javascript prevents me from do the last option below?

function GetDateTime(value){
    if (value == null) return "";
    var pattern = /Date\(([^)]+)\)/; //date format from server side
    var results = pattern.exec(value);
    var dt = new Date(parseFloat(results[1]));
    var tMonth = dt.getMonth() + 1;
    var tDay = dt.getDate();
    
    return (tMonth.toString().length > 1 ? tMonth : "0" + tMonth) + "/" + (tDay.toString().length > 1 ? tDay : "0" + tDay) + "/" + dt.getFullYear();
} // function GetDateTime



...
// This works
{
    "data": "Date",
    "autoWidth": true,
    "render": function (value) {
        return GetDateTime(value);
    }    
}
...
// This works
{
    "data": "Date",
    "autoWidth": true,
    "render": function (value) {
        // The exact same code in GetDateTime(value)
    }    
}
... 
// This does not work
{
    "data": "Date",
    "autoWidth": true,
    "render": GetDateTime(value)
    }    
}

As far as I'm aware, the last one is doing the exact same thing, however when I do that, it throws an error saying "value is undefined." How is value any more defined than with the anonymous function declaration? What about that causes javascript to pass a value in there as opposed to inside an implicit function call?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This would work because it passes the value of the property to your function:

{
    "data": "Date",
    "autoWidth": true,
    "render": value => GetDateTime(value)
}
about 4 years ago · Juan Pablo Isaza Denunciar
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