Skip to content
New issue

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

Bound function as a method #3517

Closed
adeyems opened this issue Aug 1, 2023 · 2 comments
Closed

Bound function as a method #3517

adeyems opened this issue Aug 1, 2023 · 2 comments

Comments

@adeyems
Copy link

adeyems commented Aug 1, 2023

function f() {
    alert(this) // or console.log(this) in NodeJS environment
}

let user = {
    g: f.bind(null)
}

user.g()

I did not get null. The Global Object is still displayed. Window in the browser environment and NodeJs Global Object in NodeJS environment.

@vsemozhetbyt
Copy link
Contributor

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind#parameters

If the function is not in strict mode, null and undefined will be replaced with the global object

@adeyems
Copy link
Author

adeyems commented Aug 1, 2023

That works. Thanks.

@adeyems adeyems closed this as completed Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants