class Foo {
constructor(bar) {
this.bar = bar
}
getBar() {
return this.bar
}
}
function unmethodize(f) {
return function(object, ...args) {
return f.apply(object, args)
}
}
const unmethodizedGetBar = unmethodize(Foo.prototype.getBar)
function test() {
foos = [new Foo(1), new Foo(2), new Foo(3)]
return foos.map(unmethodizedGetBar)
}
I know about foos.map(foo => foo.getBar())
etc.
I simply want a version of getBar
that takes the "this" object as its first parameter. Does it already exist somewhere, or must I create it via unmethodize
or some such?