Inside the callback of an event, how do I get the scope outside the function? Specifically, in the following scenario, I want the web3 object: (using truffle-contracts and web3 1.0 here)

const web3 = new Web3(someProvider);

myContract.deployed().then(function(instance) {
    // both ways work
    instance.myEvent({}, function(error, event) {
        // here, I want to use web3

If you define a variable in Javascript without const or var clause, it will be defined globally. So you can write:

web3 = new Web3(someProvider);

For more information about variables scope in Javascript see: https://www.w3schools.com/js/js_scope.asp

Not the answer you're looking for? Browse other questions tagged or ask your own question.