-
Notifications
You must be signed in to change notification settings - Fork 70
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
Proposed question: 5 ways to call a JavaScript function? #12
Comments
+1, only I would rather call it "5 ways to set function execution context" |
I second dpashkevich on this. Good question though! |
Good suggestion, I don't disagree that it's good knowledge to have. But, I feel like aspects of that blog post are already covered…
|
Right, but it's a less direct question. You can see how the person understands that all above is connected. |
I'm up for adding it. Care to write a question, and an example answer? |
I kept going back and forth with the question phrasing, here's the best I've come up so far: Question Answer
foo(); // this === global inside the function
obj.foo(); // this === obj inside the function
foo.call(obj, param1, param2, param2); // this === obj
foo.apply(obj, [param1, param2, param2]); // this === obj
new Foo(); // this === empty object with Foo's prototype |
+1 |
This is a question I was once asked in a job interview. Might be appropriate here.
http://devlicio.us/blogs/sergio_pereira/archive/2009/02/09/javascript-5-ways-to-call-a-function.aspx
The text was updated successfully, but these errors were encountered: