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

149
Vistas
How do you represent a class as a function in JavaScript

Per Classes in MDN

Classes are in fact "special functions"

How would something like

class Foo {
  constructor(x) {
    this.x = x;
  }

  foo() {}

}

be translated to just function (ignoring the "hoisting" feature)

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

0

// declare the "class"
function Foo (x) {
  this.x = x;
}

// declare the instance method
Foo.prototype.foo = function () {
  return 'i am foo';
}

// create an instance
const f = new Foo(42);

// invoke its methods
console.log(f.foo()); // 'i am foo'

// access its properties
console.log(f.x); // 42

about 4 years ago · Juan Pablo Isaza Denunciar

0

Non hoisted, (as much as constructor functions based on class syntax are not hoisted,) due to an immediately invoked function expression (IIFE) which serves as module pattern ...

const Foo = (function () {    //  class Foo {
                              //
  function Foo(x) {           //    constructor(x) {
    this.x = x;               //      this.x = x;
  }                           //    }
  function foo() {            //    foo() {
  }                           //
  Foo.prototype.foo = foo;    //    }
                              //
  return Foo;                 //
                              //
}());                         //  }
about 4 years ago · Juan Pablo Isaza Denunciar

0

Well really everything is objects - a class is simply a blueprint for an object that has some methods and some values. It's all objects with features that can either store values or transform values.

A class is something - a function does something. Calling it a special function is if anything unnecessary at best and confusing at worst.

Basically - don't worry about it.

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