Change the view on JavaScript

Source: Internet
Author: User

Today I read a book called "jquery practice" and ran to the final Appendix (JavaScript is required). After reading it, I found that I had a big misunderstanding about JavaScript, because I used Java and C #, both of which have less or less influence on my thinking, and the magic of grammar interferes with my understanding, let everyone better understand.

JavaScript Functions are considered objects. They are of the same type as other JavaScript objects, such as string, number, and date. Functions are also defined by the Javascript constructor. Therefore, a function is also called a first-class object. For example, we usually write this statement, Function dosomethingwonderful () {<br/> alert ('Does something wonderful '); <br/>} However, we can help you understand the above, Dosomethingwonderful = function () {<br/> alert ('Does something wonderful '); <br/>} ThisIt means to assign the function to the top-level variable (the property of window ).
Let's take a deeper look and introduce this into our explanation, VaR O1 = {handle: '01'}; <br/> var O2 = {handle: '02'}; <br/> var O3 = {handle: '03'}; <br/> window. handle = 'window'; <br/> function whoami () {<br/> return this. handle; <br/>}< br/> o1.identifyme = whoami; <br/> alert (whoami (); <br/> alert (o1.identifyme ()); <br/> alert (whoami. call (O2); <br/> alert (whoami. apply (O3 ));
The answer is what I want you to guess (window, O1, O2, O3). Here we should note what this refers to in the context of the function. Call call () and apply () to make the function look like an O2 method, but in fact this function is not associated with O2 (even the property of O2 is not ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.