We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
const person = { firstName: "", lastName: "", getFullName: function() { return `${this.firstName} ${this.lastName}`; } } const Choi = { firstName: "Hyuno", lastName: "Choi", } let getFullNameOfChoi = person.getFullName.bind(Choi); console.log(getFullNameOfChoi()); // Hyuno Choi
Choi
person.getFullName
this
const Choi = { firstName: "Hyuno", lastName: "Choi", getFullName: function() { return `${this.firstName} ${this.lastName}`; } } setTimeout(Choi.getFullName, 1000); // undefined undefined
Hyuno Choi
setTimeOut
Choi.getFullName
setTimeout(Choi.getFullName.bind(Choi), 1000); // Hyuno Choi
The text was updated successfully, but these errors were encountered:
No branches or pull requests
다른 객체에서 메소드를 빌려 사용할 때
Choi
객체는 아무런 메소드가 없음.person.getFullName
메소드에Choi
를 바인딩하여Choi
의this
맥락을 사용할 수 있다.this 맥락을 유지해야 할 때
Hyuno Choi
가 출력될 것 같지만 아무것도 출력되지 않음.setTimeOut
함수에Choi.getFullName
메소드가 콜백으로 전달되는 순간 해당 메소드의 this 맥락이 사라지기 때문.Choi.getFullName
메소드를 전달해주는 동시에Choi
객체를 바인딩하면 this 맥락을 유지할 수 있음.Ref
The text was updated successfully, but these errors were encountered: