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

112
Vistas
What is the name of the technique of doing object oriented design in JavaScript without class or prototype?

Years ago I used this technique because I did not know how to do it "right" with prototype. It's a technique I call Christmas tree OOD. You make a function which is like a constructor that makes a new object, attaches new properties to it, like a Christmas tree, and return the reference to it. Here is an example:

function RigidBody() {
    const newRB = document.createElement('canvas');
    
    newRB.dataMember = 5;
  
    newRB.memberFunction = function() {
        // do important rigid body stuff
    }

    return newRB;
}

Then you can use this function as a kind of base object to make other derived objects.

function Ship(locX, locY) {
    const newShip = new RigidBody();

    newShip.otherDataMember = 34;

    newShip.otherMemberFunction = function() {
        // some other important ship specific stuff to do
    }

    return newShip;
}

You can see that this simple thing I did can make N number of objects with a full "class" hierarchy of objects. Then you can just make an object of the derived object.

    const myShip = new Ship(100, 200);

I use class now and I don't plan on using this in the future but I'm curious to know if others have used this technique and if it has a name.

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

0

It's still called OOP, since you're working with objects. Redefining member functions inside the constructor (when not necessary for this-binding) instead of putting them on the prototype is considered a bad practice, but doesn't change functionality or modelling.

Your technique for creating derived objects is known as parasitic inheritance, a term coined by Douglas Crockford afaict.

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