I have problem with this code recently:
function doSth() {
console.log(this);
}
const fWithMeteorEnv = Meteor.bindEnvironment(doSth);
fWithMeteorEnv.call({}); // expect to see a plain object in console
What I expect is to see a plain object in console but not, it is something else. It seems that Meteor.bindEnvironment
prevents the returned function to be called with another context. Are there any way to get around this?
I think that what you're trying to achieve is not possible, i.e. you will need to bind your context at the moment you're calling Meteor.bindEnvironment
. You can do it with .bind()
, e.g.
const fWithMeteorEnv = Meteor.bindEnvironment(doSth.bind(context));
or you can pass the context as the third argument to Meteor.bindEnvironemnt()
, e.g.
const fWithMeteorEnv = Meteor.bindEnvironment(doSth, null, context);
The second argument is an exception callback.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With