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

143
Views
Class vs alternate ways of accomplishing it

Are the following three ways of 'building a class' effectively the same? If not, what might be some of the more subtle or not-so-subtle differences?

class Person {
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }
    get_birth_year() {
        return new Date().getFullYear() - this.age;
    }
}
let p = new Person('Bob', 33);
console.log(p.get_birth_year());

function Person(name, age) {
    this.name = name;
    this.age = age;
}
Person.prototype.get_birth_year = function() {
    return new Date().getFullYear() - this.age;
}
let p = new Person('Bob', 33);
console.log(p.get_birth_year());

function Person(name, age) {
    let person = Object.create(Person.prototype);
    person.name = name;
    person.age = age;
    return person;
}
Person.prototype.get_birth_year = function() {
    return new Date().getFullYear() - this.age;
}
let p = Person('Bob', 33);
console.log(p.get_birth_year());

about 4 years ago · Juan Pablo Isaza
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!