Example: Using .call() to pass context

by Matthew Marcus

JavaScript

function Bar(){
    this.baz = "BAZ";
    
};

Bar.prototype.run = function(){
    return foo.call(this);
};

var foo = function(){
    return 'FOO' + this.baz;
};

var bar = new Bar();

console.log(bar.run());