Skip to content

Instantly share code, notes, and snippets.

@chengjianhua
Last active March 17, 2018 05:21
Show Gist options
  • Save chengjianhua/08531921eef66355b52a9c5b016f1c9a to your computer and use it in GitHub Desktop.
Save chengjianhua/08531921eef66355b52a9c5b016f1c9a to your computer and use it in GitHub Desktop.
test the behavior of bound function
function Func() {
this.a = 1;
console.log('this', this);
}
console.group('Func.invoke');
console.log(Func());
console.groupEnd();
console.group('i1');
const i1 = new Func();
console.log(i1);
console.groupEnd();
const obj1 = { b: 1 };
const FuncBoundObj1 = Func.bind(obj1);
console.group('Func');
console.dir(Func);
console.groupEnd();
console.group('FuncBoundObj1');
console.dir(FuncBoundObj1);
console.groupEnd();
console.group('FuncBoundObj1.invoke');
FuncBoundObj1();
console.groupEnd();
console.group('FuncBoundObj1.new');
const obj2 = new FuncBoundObj1();
console.log(obj2);
console.groupEnd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment