Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!