/* shows how to use call() and apply() * essentially given a method called .bar(), instead of calling it directly with * use of double parens we append .call(instance [, arg1, arg2, ...]), where * apply takes array of args */ function foo() { this.tag = 'bar'; this.bar = function(txt) { console.log(txt + this.tag); } } var bar = new foo(); bar.bar('foo') /* first arg of call is the class instance, could be 'this' if we were in one */; bar.bar.call(bar, 'foo'); /* apply is similar but it accepts on array of arguments */ bar.bar.apply(bar, ['foo']);