Non-mainstream JavaScript teaching (1)

Source: Internet
Author: User

Question:

This article has the following purposes:

1. less active recently.

2. complain that all kinds of teaching is getting worse and worse. Then, if you try it, you will find it hard to write.

 

So I decided to write. Target readers: people who have not written JavaScript or are not poisoned by messy teaching materials.

In this way, you can only be poisoned by me. Pai_^

 

Body:

I have never liked a book like the Javascript authoritative guide, which is an authoritative but nonsense book.

According to the same principle, I do not like to read modern Chinese dictionaries.

 

I like short and concise books like the essence of JavaScript language.

In fact, this description is exactly the description of the Javascript language.

 

Javascript runs on a browser, so you think so for the moment.

Generally, people who come to the blog Park do not have any programming experience. So I will not mention simple syntaxes such as if, else, while, and. Enter the text directly.

 

Javascript is an object-based language. You can also say object-oriented. That's what it means.

However, the abnormal point in Javascript is that classes are also objects.

Well, this is not exactly the case. We should say there is no class. Then JavaScript developers use various abnormal methods to simulate classes.

 

Let's start with a simpleProgramStart. I prefer direct, not implicit.

Let's write the following:Code:

(Function(Window, undefined ){
Document. Write ('Hello, world!');
}) (Window );

Remember that JavaScript is a very strange language and is very suitable for 13. Therefore, it cannot be written too easily ..

--!

The running mode is to put the JS file into the script tag. Or directly add the code to the script tag.

This is not demonstrated in detail. This code will display a hello, world! Come out

 

Explain the entire code step by step:

The function keyword can be used to create a function)

() Is used to add parameters.

This function can be run immediately.

So the whole is equivalent:

 

VaR Afunc =   Function (Window, undefined ){
Document. Write ( ' Hello, world! ' );
}
Afunc (window );

Then, what is the use of window and undefined?

This is simple. They are useless.

=. =

Generally, JS files are written in this way. The reason is:

1 compression.

We know that JS files will be compressed into smaller, more refined, and more obscure code (it is said that some people can directly write code without compression, which is amazing) to reduce the file size. Windows and undefined are very common. Therefore, you can compress them into non-global variables. This will greatly reduce the file size.

2. If two parameters are declared for a function, but only one parameter is passed during the call, the second value will be assigned undefined. You see, I made a debut ..

 

Some people may say that the converted Code cannot be written like this:

 

Function Afunc (window, undefined ){
Document. Write ( ' Hello, world! ' );
}

Afunc (window );

Remember that this is not good. He is too easy to understand by "non-JavaScript programmers. We cannot. In this way, we cannot achieve the purpose of showing that we are different, and we cannot achieve the purpose of 13.

Another more important reason is that we will talk about it next time.

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: info-contact@alibabacloud.com 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.