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

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

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 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!