Skip to content

Instantly share code, notes, and snippets.

@oviniciusfeitosa
Created October 16, 2019 15:15
Show Gist options
  • Save oviniciusfeitosa/546a951d4faa9e4d9fb796e031afe969 to your computer and use it in GitHub Desktop.
Save oviniciusfeitosa/546a951d4faa9e4d9fb796e031afe969 to your computer and use it in GitHub Desktop.
Javascript execute callback.md
function Thing(name) {
    this.name = name;
}
Thing.prototype.doSomething = function(callback) {
    callback.call(this);
}

function foo() {
    alert(this.name);
}

var t = new Thing('Joe');
t.doSomething(foo);  // Alerts "Joe" via `foo`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment