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

108
Views
Passing "this" with bind returns undefined. Returning "this" returns windows object
  class ObjectMapping {
    constructor(value) {
        this.value = value;
    }
      map(func) {
        let b = func.bind(this)()
        console.log(b);
    }
  }
  
  const m = new ObjectMapping({ abc: 'abc',
      def: 'def' });
  const func = (value) => {
      return this[value]
  };
  
  m.map(func);

The func function is part of my assignment so it can't be changed but I can mess around with it to see what it returns.

const func = (value) => {
    return this //returns windows object
};

When I set it to just this, I get back the windows object regardless of what I pass in.

const func = (value) => {
    return value //returns undefined
};

When I bind it, it returns undefined.

map(func) {
   let key = Object.keys(this.value)[0] //key = abc
   let b = func(key)
   console.log(b);
}
const func = (value) => {
    return this.value
};

I tried passing in the the key but I still get undefined. How do I pass in an object and not get back the windows 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!