Crossing boundaries: JavaScript language Features

Source: Internet
Author: User
Tags new set object model

JavaScript is often considered a trivial part of the programming language. This idea can be "attributed" to its development tools, complex and inconsistent Document object models for HTML pages, and conflicting browser implementations. But JavaScript is definitely more than just a toy. In this article, Bruce Tate introduces you to the language features of JavaScript.

Almost every WEB developer has had the experience of cursing JavaScript. This controversial language is affected by its complex programming model called the Document Object Model (DOM), poor implementation and debugging tools, and inconsistent browser implementations. Until recently, many developers thought that Javascript was the best way to avoid the worst, but it was just a toy.

However, JavaScript is becoming increasingly important, and it has become a scripting language widely used in WEB development. The revival of JavaScript has led some industry leaders to start re-examining the programming language. Programming techniques such as AJAX (asynchronous JavaScript + XML) make Web pages more attractive. The complete Web development framework, such as the Apache Cocoon, makes JavaScript more and more useful, making it not limited to a simple script for making Web pages. A macromedia of JavaScript, called ActionScript, also drives the development of the Flash client framework for the system. The implementation Rhino running on the JVM makes JavaScript the preferred scripting language for Java™ developers (see Resources).

My friend and colleague Stuart Halloway, an Ajax expert, has made the opening remarks in his JavaScript class: "By 2011, JavaScript will be recognized as a language with the new set of features needed to develop modern applications." 。 He went on to say that JavaScript programs are 10 times times closer than similar Java programs and continue to show some of the language features that make them so.

In this article, I'll take you through some of the features of JavaScript to see how these features make it so appealing:

Higher-order functions: a higher-order function can either take a function as an argument or return a function. This feature allows JAVASCRIPT programmers to manipulate functions in ways that the Java language cannot provide.

Dynamic type: JavaScript can be more accurate and flexible by delaying binding.

Flexible object Model: JavaScript object models inherit in a relatively uncommon way-called prototypes-rather than the more common class-based object model in the Java language.

You may already be familiar with the dynamic type model, functional programming in the form of higher-order functions, and the open object model, as I have already covered in other articles across the boundary. If you've never had any formal JavaScript development, you'd probably think that these features are very complex languages, such as Python, Lisp, Smalltalk, and Haskell, not what languages like JavaScript can provide. Therefore, I will use the actual code examples to illustrate these concepts.

Start now

You do not need to set JavaScript. If you can read this article in a browser, you are ready to go. All of the programming examples included in this article can be run in most browsers. I'm using Firefox.

Use JavaScript contained in the <script type= ' Text/javascript ' > and </script> tags to load a simple Web page. Listing 1 can show Hello, world text:

Listing 1. Hello, World

<script type='text/javascript'>
alert('Hello, World.')
</script>

To run this code, you only need to create a file named Example1.html. Copy the code in Listing 1 to the file and load the file in the browser (see the Download section for all the sample HTML files used in this article). Note that the code executes immediately each time the page is overloaded.

Alert is a function call with only one string as a parameter. Figure 1 shows a warning box that pops up from the code in Listing 1, displaying the text "Hello, World". If the code is within the HTML body (no body is currently specified, the browser accepts irregular HTML and the entire page is processed as a body). Once the page is loaded, JavaScript executes immediately.

Figure 1. Hello, World

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.