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

227
Vistas
Can new be called on anything other than a class/function

Is it possible to directly modify objects so that they can be created with the new keyword, or does that only apply to functions/classes? As an example:

const bird = {
    swim() {return 'Swim';},
    fly() {return 'Fly';}
};
let b1 = Object.create(bird);

bird.constructor = function(){console.log('via constructor')};
let b2 = new bird();

There's no practical use of this, I'm more just learning things and seeing how new works and such.

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

0

No.

Using new results in EvaluateNew being called, which does

  1. If IsConstructor(constructor) is false, throw a TypeError exception.

which does

  1. If argument has a [[Construct]] internal method, return true.

and that internal property is only permitted on functions:

A constructor is an object that supports the [[Construct]] internal method. Every object that supports [[Construct]] must support [[Call]]; that is, every constructor must be a function object.

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