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

129
Views
Why I'm getting "Object.defineProperty called on non-object" when using a binded function as 1st parameter in Object.defineProperty

I'm trying to bind the this keyword of a function and use the Function as with object dot notation (as Functions are also objects). I figured out using the object literal 'get' to do something like: myFunction.whatever (instead of myFunction().whatever).

Code is:

let template = {name: "William"};
let aux = function(){}
callTo = aux.bind(template);

Object.defineProperty(callTo.prototype, "scream", {
    get: function() {
        console.log(this);
        return "Hi, " + this.name;
    }
});
myObj = new callTo();
myObj.scream;

This causes the: "Object.defineProperty called on non-object" error However, if I bind in each property defined with "get" it will correctly work.

let template = {name: "William"};
let callTo = function(){}

Object.defineProperty(callTo.prototype, "scream", {
    get: function() {
        console.log(this);
        return "Hi, " + this.name;
    }.bind(template)
});
myObj = new callTo();
myObj.scream;  // Outputs Hi William

The working approach works but obligues me to add a bind() at the end of each propery. So question is:

¿Why is first code failing?

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!