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

93
Views
javascript prototype properties operation

I want to add a prototype parameter to JavaScript Object witch returns a sum of other parameters.

Why does this work ?:

function Item() {
    this.a = 2;
    this.b = 3;
    this.c = this.a + this.b;
}

let it = new Item();
console.log(it.c); //5

And this does not ???:

function Item() {
    this.a = 2;
    this.b = 3;
}
Item.prototype.c = this.a + this.b;
console.log(it.c); // Nan

How to access a property so I can do operations in prototypes properties ?

Or need I to always declare it in the constructor of the Object ?

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!