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?