Section one: JavaScript Encoding and debugging

Source: Internet
Author: User

(Transferred from Lao Hui's blog)

First, preface

工欲善其事, its prerequisite. Between the thing and the device is corresponding, what to do with what tool, which is to be fastidious.

For JavaScript (not just JavaScript, of course), I think it would be better to differentiate between the tools of learning and the tools of production. In production, everything is aimed at productivity, and using a powerful IDE is not the only option. and learning, automation is too high tools, but will hinder your learning. Of course, if you are a skilled engineer, you can not consider these problems.

My habit is that when it comes to learning a new technology, or another language, I like to work with manual code, using a simple, handy text editor like EditPlus to write code, and compiling it manually using the command line, which gives me insight into the essence of language or technology and more detail. Then, I will find a representative open source project, using the IDE to analyze its source code, so as to understand how the language or technology in the production environment to solve the actual problem.

Second, the Coding tool

As long as it is a tool for editing text, it can be encoded in JavaScript. However, considering the performance, efficiency, and convenience, we use more editplus, UltraEdit, EmEditor, notepad++, Sublime Text, and Webstorm, Visual studio and so on. The latter two are professional ides and belong to the heavyweight development tool.

EditPlus Small and convenient, powerful, use is very handy. You typically organize and manage project files through a catalog.

However, editplus default use of IE browser, and is a "seamless browser", open browser page, also in the editplus of a sub-document page, the browser can not use the "developer Tools" for complex JS code debugging is very inconvenient. You can modify your browser's configuration by using the preferences settings.

In this way, you can open an external browser when browsing the Web page and press F12 to debug.

EditPlus is a fee software, if you are not willing to pay to register, you can use notepad++. Notepad++ can use Project management projects.

You can then "add files from a directory" to add your project files to the project for easy administration.

Of course, don't forget to save the workspace.

You can use the shortcut keys to open the browser browsing page, debugging programs. You can modify the shortcut keys to run the browser to suit your personal habits.

Sublime text is a powerful code editor that is paid for software, but can be tried indefinitely. Sublime text can be extended through plugins, enhanced features, so powerful, and very fun, by programmers love. There are two main ways to install a plugin.

Installation method one: Direct installation.

You can download the plugin installation package directly and unzip it to the packages directory. The packages directory can be viewed through the menu->preferences->browse packages.

Installation method Two: Install using the Package control component.

From the menu->perferences->package control, bring up the install package and select the plug-in you want to install in the list.

For example, we hope that in the sublime text work environment can open the browser directly to see the effect of the Web page debugging, you can install a very useful right-click menu Enhancement Plugin sidebarenhancements. The right-click menu function in the folders bar on the left side of sublime text is enhanced.

The plugin also allows us to customize the shortcut settings using which browser, click on the menu bar preferences->package setting->side bar->key Building-user, set.

This way, you can open the browser to view the Web page directly via the right-click menu or by using the shortcut key.

Install the Sublimetmpl plugin to quickly generate file templates, such as shortcut keys "ctrl+alt+h" to generate HTML file templates.

Installs the better completion plugin, supports JavaScript, JQuery, Twitter bootstrap frame, HTML5 Tag property hints.

Note the configuration file, which first copies the configuration contents from the Preferences->package setting->sublime better completion->settings-default to preferences- >package setting->sublime better Completion->settings-user, and then make modifications.

For example, to enable jquery AutoComplete now, modify "jquery": false, "for" "jquery": true, ".

With configuration, you can run JavaScript within sublime text without having to open an external browser for browsing and debugging to see how the code works.

First step: Install node. js

After installation, see if the NODEJS environment variable is configured.

Then, on the command line, enter the node command to test it.

Step Two: Add the build system

Click menu Tools, build system, New build system, enter the configuration information and save it.

JavaScript can then be run directly within the sublime text.

Third, code debugging

No one can write code overnight. Verify ideas, track bugs, resolve errors, and debug the whole process along with our coding. Good debugging methods and tools can greatly improve our coding efficiency.

We typically run our code in a browser, and we can verify that the output is consistent with what we expected by prompting information such as the alert statement and the Console.log statement. You can also use F12 to bring up the browser's developer tools, to debug the code breakpoints.

For example, there is a function sayhello, we want to debug it.

function SayHello (name) {

var msg = "Hello," +name;

Console.log (msg);

}

We wrote two files with EditPlus.

Test.js

Test.html

According to the above, we can set EditPlus to call the external browser to open the HTML page, and through the shortcut key F12 to bring up the browser developer tools, refresh the page, we see the program output results in the console.

You can click "Source" to view the source code, and click on the mouse to add a breakpoint, refresh the page to reload the page, you can debug the breakpoint.

Of course, the powerful IDE, which integrates coding and debugging, is convenient to use. Convenience comes at a cost, and these tools increase efficiency for your production and you'll have to hand over your money. Webstorm, Visual Studio, and so on, is such a tool. Here is the most powerful, most convenient visual Studio, other tools that you can choose to learn and use according to your preferences.

Create a Web site project first. For simplicity, we create an empty project and then copy the two files to the project.

This time we add the breakpoint directly to the page.

Run the program, it will stop at the breakpoint place.

Step through the process to see the results of the program running.

Iv. Summary

JavaScript, which is a scripting language designed for Web browsers, has been widely used in a variety of software applications in recent years. There is not only JavaScript code running on the server, but also JavaScript code to drive iOS and Android apps, and even some to control the robot. So what kind of tools to use, according to their own work scene and needs, choose the right tool.

Section one: JavaScript Encoding and debugging

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.