Che cos'è "JavaScript semplificato"?

3

Douglas Crockford fa riferimento a JavaScript semplificato in questo articolo su Precedenza dell'operatore top down . Sfortunatamente egli fa solo riferimenti ad esso in questo articolo. La migliore spiegazione che ho trovato qui . Ma ancora non ho idea di cosa sia realmente.

Che cos'è JavaScript semplificato?

    
posta Derek Adair 02.01.2011 - 03:05
fonte

2 risposte

3

Douglas Crockford, nel suo libro JavaScript: The Good Parts (pagina 98-99), descrive JavaScript semplificato:

I was invited last year to contribute a chapter to Andy Oram’s and Greg Wilson’s Beautiful Code (O’Reilly), an anthology on the theme of beauty as expressed in com- puter programs. I wanted to write my chapter in JavaScript. I wanted to use it to present something abstract, powerful, and useful to show that the language was up to it. And I wanted to avoid the browser and other venues in which JavaScript is typecast. I wanted to show something respectable with some heft to it.

I immediately thought of Vaughn Pratt’s Top Down Operator Precedence parser, which I use in JSLint (see Appendix C). Parsing is an important topic in computing. The ability to write a compiler for a language in itself is still a test for the complete- ness of a language.

I wanted to include all of the code for a parser in JavaScript that parses JavaScript. But my chapter was just one of 30 or 40, so I felt constrained in the number of pages I could consume. A further complication was that most of my readers would have no experience with JavaScript, so I also would have to introduce the language and its peculiarities.

So, I decided to subset the language. That way, I wouldn’t have to parse the whole language, and I wouldn’t have to describe the whole language. I called the subset Simplified JavaScript. Selecting the subset was easy: it included just the features that I needed to write a parser. This is how I described it in Beautiful Code:

Simplified JavaScript is just the good stuff, including:

Functions as first class objects: Functions in Simplified JavaScript are lambdas with lexical scoping.

Dynamic objects with prototypal inheritance: Objects are class-free. We can add a new member to any object by ordinary assignment. An object can inherit members from another object.

Object literals and array literals: This is a very convenient notation for creating new objects and arrays. JavaScript literals were the inspiration for the JSON data interchange format.

The subset contained the best of the Good Parts. Even though it was a small language, it was very expressive and powerful. JavaScript has lots of additional features that really don’t add very much, and as you’ll find in the appendixes that follow, it has a lot of features with negative value. There was nothing ugly or bad in the sub- set. All of that fell away.

    
risposta data 02.01.2011 - 06:10
fonte
2

Douglas Crockford (in quell'articolo) scrive un parser (in JavaScript) che gestisce un set semplificato di JavaScript.

    
risposta data 02.01.2011 - 03:23
fonte

Leggi altre domande sui tag