Last active
March 17, 2018 05:21
-
-
Save chengjianhua/08531921eef66355b52a9c5b016f1c9a to your computer and use it in GitHub Desktop.
test the behavior of bound function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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