Bind, Call, Apply Test
by rulokc
HTML
<div id="log"></div>
JavaScript
function echo(s) {
var div = document.getElementById('log');
div.innerHTML = div.innerHTML + '<br/>' + s;
}
function hello(name) {
var greeting = this.greeting;
echo(greeting + ' ' + name + '!');
}
hello();
hello('World');
hello.bind({greeting:'[via bind] Hello'})('World');
hello.call({greeting:'[via call] Hello'}, 'World');
hello.apply({greeting:'[via apply] Hello'}, ['World']);