Skip to content

Instantly share code, notes, and snippets.

@tanmancan
Last active January 17, 2017 13:07
Show Gist options
  • Save tanmancan/57748586a1874a9dc71d3c84fa2427ae to your computer and use it in GitHub Desktop.
Save tanmancan/57748586a1874a9dc71d3c84fa2427ae to your computer and use it in GitHub Desktop.
bind, call, apply demo
function nonbinded(para, para2, para3) {
console.log('this:', this);
console.log('para:', para, para2, para3);
}
console.log('Call,Appy,Bind ==============');
console.log('nonbinded()----------------');
nonbinded('test-para', 'test-para2', 'test-para3');
console.log('.call()----------------');
nonbinded.call('test-this-call','test-para-call', 'test-para2-call', 'test-para3-call');
console.log('.apply()----------------');
nonbinded.apply('test-this-apply',['test-para-apply', 'test-para2-apply', 'test-para3-apply']);
console.log('.bind()----------------');
var binded = nonbinded.bind('test-this-bind');
binded('test-para-bind', 'test-para2-bind', 'test-para3-bind');
console.log('Call,Apply,Bind Event ==============');
document.addEventListener('click',nonbinded);
document.addEventListener('click',binded);
console.log('==============');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment