Summary
In a recent IBM DeveloperWorks article, Bruce Tate discusses some of JavaScript's lesser-known language features, such as prototype-based objects, dynamic types, and support for higher-order functions.
Advertisement
JavaScript is both the black sheep of current programming languages, and also the language that many people wish was more ready for prime-time application development, according a recent IBM DeveloperWorks article by Bruce Tate, JavaScript's Language Features.
Tate explains that far from being an impoverished language in terms of features, JavaScript supports a large number of state-of-the-art programming techniques, such as higher-order functions well-known in the functional programming community:
Functions are first-class objects in JavaScript, and I can manipulate them freely... C developers think of this concept as a function pointer, but JavaScript's notion of higher-order functions is much more powerful. This feature gives JavaScript programmers the ability to deal conceptually with actions, or functions, as easily as they deal with other variable types.
Using a function as a function argument, or returning a function as a value, elevates this abstraction into the realm of higher-order functions... Higher-order functions form the foundation of functional programming, which most believe represents a higher level of abstraction than pure object-oriented programming.
Tate also discusses JavaScript's prototype-based object system:
JavaScript represents objects as nested functions [and] bases object construction on a prototype, or an existing instance of an object, rather than a class template...
Many have used [JavaScript]'s object model to create surprisingly sophisticated, well-designed, object-oriented software. But the object model, especially for inheritance, is not what you're used to.
The Java language is class-based. When you build applications, you build a new class as a template for all objects. Then, you call new to instantiate that template, creating a new object. In JavaScript, you instead create a prototype, which is an instance that creates all future objects.
A more detailed explanation of prototype-based objects is given in Artima's interview with Scott Blum, the Google engineer behind the Google Web Toolkit's Java-to-JavaScript compiler, Compiling Java to JavaScript.
What do you think of JavaScript as a programming language?