Javascript 2.0: Evolving a Language for Evolving Systems

Total Page:16

File Type:pdf, Size:1020Kb

Javascript 2.0: Evolving a Language for Evolving Systems JavaScript 2.0: Evolving a Language for Evolving Systems Waldemar Horwat [email protected] Abstract JavaScript 2.0 is the next major revision of the JavaScript language. Also known as ECMAScript Edition 4, it is being standardized by the ECMA organization. This paper summarizes the needs that drove the revision in the language and then describes some of the major new features of the language to meet those needs — support for API evolution, classes, packages, object protection, dynamic types, and scoping. JavaScript is a very widely used language, and evolving it presented many unique challenges as well as some opportunities. The emphasis is on the rationale, insights, and constraints that led to the features rather than trying to describe the complete language. Netscape browsers through an interface 1 Introduction called LiveConnect. JavaScript as a language has computational 1.1 Background facilities only — there are no input/output JavaScript [6][8] is a web scripting language primitives defined within the language. In- invented by Brendan Eich at Netscape. This stead, each embedding of JavaScript within language first appeared in 1996 as a particular environment provides the means JavaScript 1.0 in Navigator 2.0. Since then to interact with that environment. Within a the language has undergone numerous addi- web browser JavaScript is used in conjunc- tions and revisions [6], and the most recent tion with a set of common interfaces, in- released version is JavaScript 1.5. cluding the Document Object Model [11], which allow JavaScript programs to interact JavaScript has been enormously successful with web pages and the user. These inter- — it is more than an order of magnitude faces are described by separate standards more widely used than all other web client and are not part of the JavaScript language languages combined. More than 25% of web itself. This paper concentrates on the pages use JavaScript. JavaScript language rather than the inter- faces. JavaScript programs are distributed in source form, often embedded inside web page elements, thus making it easy to author 1.2 Standardization them without any tools other than a text After Netscape released JavaScript in Navi- editor. This also makes it easier to learn the gator 2.0, Microsoft implemented the lan- language by examining existing web pages. guage, calling it JScript, in Internet Ex- plorer 3.0. Netscape, Microsoft, and a num- There is a plethora of synonymous names ber of other companies got together and for JavaScript. JavaScript, JScript, and formed the TC39 committee in the ECMA ECMAScript are all the same language. JavaScript was originally called LiveScript standards organization [2] in order to agree on a common definition of the language. but was renamed to JavaScript just before it The first ECMA standard [3], calling the was released. JavaScript is not related to Java, although the two language implemen- language ECMAScript, was adopted by the ECMA general assembly in June 1997 as the tations can communicate with each other in ECMA-262 standard. The second edition of JavaScript 2.0: Evolving a Language for Evolving Systems 1 this standard, ECMA-262 Edition 2 [4], con- attributes and conditional compilation (Sec- sisted mainly of editorial fixes gathered in tion 8). Section 9 concludes. the process of making the ECMAScript ISO standard 16262. The third edition of the ECMAScript standard [5] was adopted in 2 JavaScript 1.5 December 1999 and added numerous new JavaScript 1.5 (ECMAScript Edition 3) is an features, including regular expressions, object-based scripting language with a syn- nested functions and closures, array and ob- tax similar to C and Java. Statements such as ject literals, the and - switch do while if, while, for, switch, and statements, and exceptions. JavaScript 1.5 throw/try/catch will be familiar to fully implements ECMAScript Edition 3. C/C++ or Java programmers. Functions, I’ve been involved at Netscape with both the declared using the function keyword, can implementation and standardization of nest and form true closures. For example, JavaScript since 1998. I wrote parts of the given the definitions ECMAScript Edition 3 standard and am cur- function square(x) { rently the editor of the draft ECMAScript return x*x; Edition 4 standard. } In Editions 1 and 2, the ECMA committee function add(a) { standardized existing practice, as the lan- return function(b) { guage had already been implemented by return a+b; Netscape, and Microsoft closely mirrored } that implementation. In Edition 3, the role of } the committee shifted to become more active evaluating the expressions below produces in the definition of new language features the values listed after the fi symbols: before they were implemented by the ven- square(5) fi 25 dors; without this approach, the vendors’ var f = add(3); implementations would have quickly di- var g = add(6); verged. This role continues with Edition 4, f(1) fi 4; and, as a result, the interesting language de- g(5) fi 11; sign discussions take place mainly within the ECMA TC39 (now TC39TG1) working A function without a return statement group. returns the value undefined. This paper presents the results of a few of Like Lisp, JavaScript provides an eval these discussions. Although many of the is- function that takes a string and compiles and sues have been settled, Edition 4 has not yet evaluates it as a JavaScript program; this been approved or even specified in every allows self-constructing and self-modifying detail. It is still likely to change and should code. For example: definitely be considered a preliminary draft. eval("square(8)+3") fi 67 eval("square = f") fi The 1.3 Outline source code for function f Section 2 gives a brief description of the square(2) fi 5 existing language JavaScript 1.5. Section 3 summarizes the motivation behind Java- 2.1 Values and Variables Script 2.0. Individual areas and decisions are covered in subsequent sections: types (Sec- The basic values of JavaScript 1.5 are num- tion 4); scoping and syntax issues (Sec- bers (double-precision IEEE floating-point tion 5); classes (Section 6); namespaces, values including +0.0, –0.0, +∞, –∞, and versioning, and packages (Section 7); and NaN), booleans (true and false), the JavaScript 2.0: Evolving a Language for Evolving Systems 2 special values null and undefined, im- strange("Apple ", false) fi mutable Unicode strings, and general ob- "Apple Hello" jects, which include arrays, regular expres- strange(20, true) fi sions, dates, functions, and user-defined ob- "40Hello" jects. All values have unlimited lifetime and The last example also shows that + is poly- are deleted only via garbage collection, morphic — it adds numbers, concatenates which is transparent to the programmer. strings, and, when given a string and a num- ber, converts the number to a string and Variables are not statically typed and can concatenates it with the other string. hold any value. Variables are introduced using var declarations as in: var x; 2.2 Objects var y = z+5; JavaScript 1.5 does not have classes; in- stead, general objects use a prototype An uninitialized variable gets the value mechanism to mimic inheritance. Every ob- undefined. Variable declarations are ject is a collection of name-value pairs lexically scoped, but only at function called properties, as well as a few special, boundaries — all declarations directly hidden properties. One of the hidden prop- within a function apply to the entire func- erties is a prototype link1 which points to tion, even above the point of declaration. another object or null. Local blocks do not form scopes. If a func- tion accesses an undeclared variable, it is When reading property p of object x using assumed to be a global variable. For exam- the expression x.p, the object x is searched ple, in the definitions first for a property named p. If there is one, function init(a) { its value is returned; if not, x’s prototype b = a; (let’s call it y) is searched for a property } named p. If there isn’t one, y’s prototype is searched next and so on. If no property at all function strange(s, t) { is found, the result is the value a = s; undefined. if (t) { var a; When writing property p of object x using a = a+a; the expression x.p = v, a property named p } is created in x if it’s not there already and return a+b; then assigned the value v. x’s prototype is } not affected by the assignment. The new function strange defines a local variable property p in x will then shadow any prop- a. It doesn’t matter that the var statement is erty with the same name in x’s prototype and nested within the if statement — the var can only be removed using the expression statement creates a at the beginning of the delete x.p. function regardless of the value of t. A property can be read or written using an At this point evaluating indirect name with the syntax x[s], where s strange("Apple ", false) is an expression that evaluates to a string (or signals an error because the global variable a value that can be converted into a string) b is not defined. However, the following representing a property name. If s contains statements evaluate successfully because the string "blue", then the expression init creates the global variable b: x[s] is equivalent to x.blue. An array is init("Hello") fi undefined 1 For historical reasons in Netscape’s JavaScript this hidden prototype link is accessible as the property named __proto__, but this is not part of the ECMA standard. JavaScript 2.0: Evolving a Language for Evolving Systems 3 an object with properties named "0", "1", method can refer to the object on which it "2", …, "576", etc.; not all of these need was invoked using the this variable: be present, so arrays are naturally sparse.
Recommended publications
  • Oral History of Winifred Mitchell Baker
    ........ Computer • History Museum Oral History of Winifred Mitchell Baker Interviewed by: Marc Weber Recorded: December 10, 2014 Mountain View, California CHM Reference number: X7311.2015 © 2015 Computer History Museum Oral History of Winifred Mitchell Baker Marc Weber: I'm Marc Weber of the Computer History Museum. And I'm here with Mitchell Baker, Chairwoman of Mozilla. Thank you so much for doing this interview. Winifred Mitchell Baker: Thanks, Marc. I'm happy to be here. The museum has been a bright spot for a long time, so I'm honored as well. Weber: Thank you. As am I. So start with a bit of your background. What is your full name? And when and where were you born? Baker: My full name is Winifred Mitchell Baker. My mom was a little eccentric though, and she never wanted me to use Winifred. So it's my first name. But in her mind, I was always Mitchell. So that's what I go by. And I was born in Berkeley in California in 1959. Weber: And tell me a little bit about your family and where you grew up. Baker: I grew up in Oakland, so the East Bay across from San Francisco. It borders Berkeley. My parents were born and raised on the East Coast and moved west, as people did in the '50s, where it seemed [like] starting a new life. They were each eccentric. And each had their own view of their world and really clear opinions. And I think some of that has rubbed off actually. Weber: So eccentric in what way? What did they do? Baker: Well, my dad was a classic entrepreneur.
    [Show full text]
  • Maelstrom Web Browser Free Download
    maelstrom web browser free download 11 Interesting Web Browsers (That Aren’t Chrome) Whether it’s to peruse GitHub, send the odd tweetstorm or catch-up on the latest Netflix hit — Chrome’s the one . But when was the last time you actually considered any alternative? It’s close to three decades since the first browser arrived; chances are it’s been several years since you even looked beyond Chrome. There’s never been more choice and variety in what you use to build sites and surf the web (the 90s are back, right?) . So, here’s a run-down of 11 browsers that may be worth a look, for a variety of reasons . Brave: Stopping the trackers. Brave is an open-source browser, co-founded by Brendan Eich of Mozilla and JavaScript fame. It’s hoping it can ‘save the web’ . Available for a variety of desktop and mobile operating systems, Brave touts itself as a ‘faster and safer’ web browser. It achieves this, somewhat controversially, by automatically blocking ads and trackers. “Brave is the only approach to the Web that puts users first in ownership and control of their browsing data by blocking trackers by default, with no exceptions.” — Brendan Eich. Brave’s goal is to provide an alternative to the current system publishers employ of providing free content to users supported by advertising revenue. Developers are encouraged to contribute to the project on GitHub, and publishers are invited to become a partner in order to work towards an alternative way to earn from their content. Ghost: Multi-session browsing.
    [Show full text]
  • A Rustic Javascript Interpreter CIS Department Senior Design 2015-2016 1
    js.rs { A Rustic JavaScript Interpreter CIS Department Senior Design 2015-2016 1 Terry Sun Sam Rossi [email protected] [email protected] April 25, 2016 Abstract trol flow modifying statements. We aimed for correctness in any language feature that JavaScript is an incredibly widespread lan- we implemented. guage, running on virtually every modern computer and browser, and interpreters such This project aimed for breadth of coverage: as NodeJS allow JavaScript to be used as a Js.rs supports more common language fea- server-side language. Unfortunately, modern tures at the cost of excluding certain edge implementations of JavaScript engines are cases. Additionally, Js.rs does not focus on typically written in C/C++, languages re- achieving optimal performance nor memory liant on manual memory management. This usage, as it is a proof-of-concept project. results in countless memory leaks, bugs, and security vulnerabilities related to memory mis-management. 2 Background Js.rs is a prototype server-side JavaScript in- 2.1 Rust terpreter in Rust, a new systems program- ming language for building programs with Rust is a programming language spear- strong memory safety guarantees and speeds headed by Mozilla. It is a general-purpose comparable to C++. Our interpreter runs programming language emphasizing memory code either from source files or an interac- safety and speed concerns. Rust's initial sta- tive REPL (read-evaluate-print-loop), sim- ble release (version 1.0) was released in May ilar to the functionality of existing server- 2015. side JavaScript interpreters. We intend to demonstrate the viability of using Rust to Rust guarantees memory safety in a unique implement JavaScript by implementing a way compared to other commonly used pro- core subset of language features.
    [Show full text]
  • 1. with Examples of Different Programming Languages Show How Programming Languages Are Organized Along the Given Rubrics: I
    AGBOOLA ABIOLA CSC302 17/SCI01/007 COMPUTER SCIENCE ASSIGNMENT ​ 1. With examples of different programming languages show how programming languages are organized along the given rubrics: i. Unstructured, structured, modular, object oriented, aspect oriented, activity oriented and event oriented programming requirement. ii. Based on domain requirements. iii. Based on requirements i and ii above. 2. Give brief preview of the evolution of programming languages in a chronological order. 3. Vividly distinguish between modular programming paradigm and object oriented programming paradigm. Answer 1i). UNSTRUCTURED LANGUAGE DEVELOPER DATE Assembly Language 1949 FORTRAN John Backus 1957 COBOL CODASYL, ANSI, ISO 1959 JOSS Cliff Shaw, RAND 1963 BASIC John G. Kemeny, Thomas E. Kurtz 1964 TELCOMP BBN 1965 MUMPS Neil Pappalardo 1966 FOCAL Richard Merrill, DEC 1968 STRUCTURED LANGUAGE DEVELOPER DATE ALGOL 58 Friedrich L. Bauer, and co. 1958 ALGOL 60 Backus, Bauer and co. 1960 ABC CWI 1980 Ada United States Department of Defence 1980 Accent R NIS 1980 Action! Optimized Systems Software 1983 Alef Phil Winterbottom 1992 DASL Sun Micro-systems Laboratories 1999-2003 MODULAR LANGUAGE DEVELOPER DATE ALGOL W Niklaus Wirth, Tony Hoare 1966 APL Larry Breed, Dick Lathwell and co. 1966 ALGOL 68 A. Van Wijngaarden and co. 1968 AMOS BASIC FranÇois Lionet anConstantin Stiropoulos 1990 Alice ML Saarland University 2000 Agda Ulf Norell;Catarina coquand(1.0) 2007 Arc Paul Graham, Robert Morris and co. 2008 Bosque Mark Marron 2019 OBJECT-ORIENTED LANGUAGE DEVELOPER DATE C* Thinking Machine 1987 Actor Charles Duff 1988 Aldor Thomas J. Watson Research Center 1990 Amiga E Wouter van Oortmerssen 1993 Action Script Macromedia 1998 BeanShell JCP 1999 AngelScript Andreas Jönsson 2003 Boo Rodrigo B.
    [Show full text]
  • Virtual Machines for Dynamic Languages Ausgewählte Kapitel Der Systemsoftwaretechnik, WS2021
    Virtual Machines for Dynamic Languages Ausgewählte Kapitel der Systemsoftwaretechnik, WS2021 Mark Deutel Friedrich-Alexander-University Erlangen-Nürnberg (FAU) Erlangen, Germany [email protected] ABSTRACT threading model. It is common that once a dynamic language has A common approach to execute dynamic languages is inside a vir- grown popular enough the interpreter is extended by a just-in-time tual machine (VM), usually implemented in a low level system (JIT) compiler to more efficiently execute interpreted code. language like C. Such VMs have to support the often complex However this approach does not come without problems. The syntax and semantics of the dynamic languages they are hosting. effort required to write a complete virtual machine from scratch Additionally, some properties of dynamic language code can only is huge. It also forces the language implementer to deal with plat- be inferred at runtime making the optimization of code execution form or target architecture specific details. This makes implement- another challenging task. Therefore, it is hardly possible to provide ing a VM time consuming, error prone, and complicated to port general purpose implementations that support a large range of to other systems. Additionally, modern dynamic languages like different dynamic languages. Furthermore, many commonly used Python, Ruby or JavaScript evolve rapidly and have complex syn- dynamic languages such as Python or Javascript are still evolving tax and semantics. This not only makes it hard to represent the which means that their VMs have to adapt constantly. This implies language properly in low level code, but makes maintenance of that it is necessary to write and maintain a sufficiently elaborated existing VM implementations a complicated task as well.
    [Show full text]
  • Web Evolution and Webassembly
    Web Evolution and WebAssembly COMP 520 - Special Topics Lecture I David Herrera March 29, 2019 Contents ● Limitations of JavaScript ● Evolution of Web performance via asm.js ● WebAssembly ○ Design ○ Pipeline ■ Decoding ■ Validation ■ Execution ○ Examples JavaScript - What is JavaScript? ● Dynamic, high-level language ● 10 days!, Famously designed and prototyped in ten days by Brendan Eich ● Little Performance Design: Language was not designed with performance in mind. ● Web Language: Has been the main programming language for the web since 1999 Limitations of JavaScript ● Tough Target: Dynamically typed nature makes it a “tough target” of static languages such as C and C++, as well as a relatively slow language. ● Lacks Parallelism: No real parallelism supported natively. (At least not widely supported by all browsers, or general with full control) ● Number type: Numbers are restricted to doubles, float64. This means that for instance, an i64 number cannot be represented natively in JavaScript. Let’s look at speed JavaScript as a target language for C/C++? ● Is it Doable? Yes, since JavaScript is turing complete, it should be able to represent any sort of weird semantics. JavaScript as a target language for C/C++? ● Is it Doable? Yes, since JavaScript is turing complete, it should be able to represent any sort of weird semantics. ● Is it efficient? Let’s look at Emscripten ● Emscripten is a static compiler from LLVM to JavaScript created in 2011 ● Asm.js is a“typed” subset of JavaScript which serves as a target for Emscripten ● Initial goal was to support a large enough subset of C and C++ constructs that could be run on the web.
    [Show full text]
  • Évaluation De La Valeur À L'ère Du Web: Proposition De Modèle De Valorisation Des Projets Non Marchands
    Évaluation de la valeur à l’ère du web : Proposition de modèle de valorisation des projets non marchands François Druel To cite this version: François Druel. Évaluation de la valeur à l’ère du web : Proposition de modèle de valorisation des projets non marchands. Sciences de l’ingénieur [physics]. Université d’Angers, 2007. Français. tel- 00346337 HAL Id: tel-00346337 https://tel.archives-ouvertes.fr/tel-00346337 Submitted on 11 Dec 2008 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. UNIVERSITÉ D’ANGERS ANNÉE : 2007 NUMÉRO D’ORDRE : 845 Évaluation de la valeur à l’ère du web : Proposition de modèle de valorisation des projets non marchands ÉCOLE DOCTORALE D’ANGERS THÈSE DE DOCTORAT Spécialité : SCIENCES POUR L’INGÉNIEUR Présentée et soutenue publiquement le 14 novembre 2007 à l’INSTITUT DES SCIENCES ET TECHNIQUES DE L’INGÉNIEUR D’ANGERS 62, avenue Notre-Dame du Lac, Angers par FRANÇOIS DRUEL Devant le jury d’examen composé de : Messieurs : Vincent BOLY : professeur des Universités – ENSGSI – rapporteur Fabrice PAPY : maître de conférence (HDR)– UNIVERSITÉ PARIS VIII – rapporteur Simon RICHIR : professeur des Universités – ENSAM – directeur de thèse Henri SAMIER : maître de conférences – ISTIA INNOVATION – encadrant de recherche Pascal CRUBLEAU : maître de conférences – ISTIA INNOVATION – examinateur Norbert PAQUEL : professeur associé – UNIVERSITÉ PARIS VIII – examinateur LABORATOIRE PRÉSENCE-INNOVATION —ENSAM CENTRE D’ANGERS — 4, rue de l’Ermitage 53000 LAVAL 2 Je dédie ce travail de recherche à la mémoire de JEAN-PAUL NEAU, mon premier mentor.
    [Show full text]
  • Javascript: the Good Parts Vs. Javascript: the Definitive Guide
    JavaScript: The Good Parts vs. JavaScript: The Definitive Guide For next class, read http://eloquentjavascript.net/ chapters 1-4. CS 152: Programming Language Paradigms JavaScript Prof. Tom Austin San José State University History of JavaScript 1995: Netscape hired Brendan Eich. His job: implement Scheme for Brendan Eich the web browser. After a few meetings, Scheme was deemed too weird… In 10 days, Brendan Eich wrote the initial version of JavaScript for Netscape 2.0 Beta. JavaScript • Superficially similar to Java • Primarily client-side programming • Server-side variants: –JVM: Rhino & Nashorn –Node.js • http://w3schools.com/js/default.asp JavaScript is multi-paradigm: • Imperative • Functional – "Scheme in C's clothing" • Object-oriented – Prototype-based Imperative JavaScript function addList(list) { var i, sum=0; for (i=0; i<list.length; i++){ sum += list[i]; } return sum; } Functional JavaScript var addList = function(list) { if (list.length === 0) { return 0; } return list[0] + addList(list.slice(1)); } Object-Oriented JavaScript function Adder (amount) { this.amount = amount; } Adder.prototype.add = function(x){ return this.amount + x; } var myAdder = new Adder(1); var y = myAdder.add(7); Extended JavaScript Examples (in-class) Introduction to Node.js Node.js • Server-side JavaScript • Based on Google's V8 engine • npm: Node.js package manager • http://nodejs.org/ myFile.txt This is my file. There are many like it, but this one is mine. File I/O in Node.js Callback var fs = require('fs'); function fs.readFile('myFile.txt', function(err,data) { if (err) throw err; console.log(""+data); }); console.log('all done'); Resulting Output all done This is my file.
    [Show full text]
  • Mozilla Development Roadmap
    mozilla development roadmap Brendan Eich, David Hyatt table of contents • introduction • milestone schedule • about ownership... • a new • current release • what all this does not roadmap status mean • discussion • how you can help • application architecture • summary • project • to-do list rationale management introduction Welcome to the Mozilla development roadmap. This is the third major roadmap revision, with a notable recent change to the status of the integrated Mozilla application suite, since the original roadmap that set Mozilla on a new course for standards compliance, modularity, and portability in 1998. The previous roadmap documented milestones and rules of development through Mozilla 1.3, and contains links to older roadmaps. Most of this document reflects the new application architecture proposal made last year. The effort resulting from that proposal has finally borne fruit, or to mix metaphors, hatched new application creatures: Firefox and Thunderbird. The new, significant roadmap update hoped for early in 2004 has been postponed. See Brendan's roadmap blog for thoughts that may feed into it. An interim roadmap update focused on the "aviary 1.0" 1 From www.mozilla.org/roadmap.html 4 August 2004 releases of Firefox 1.0 and Thunderbird 1.0, and the 1.8 milestone that will follow, is coming soon. We have come a long way. We have achieved a Mozilla 1.0 milestone that satisfies the criteria put forth in the Mozilla 1.0 manifesto, giving the community and the wider world a high-quality release, and a stable branch for conservative development and derivative product releases. See the Mozilla Hall of Fame for a list of Mozilla-based projects and products that benefited from 1.0.
    [Show full text]
  • Javascript: the First 20 Years
    JavaScript: The First 20 Years ALLEN WIRFS-BROCK, Wirfs-Brock Associates, Inc., USA BRENDAN EICH, Brave Software, Inc., USA Shepherds: Sukyoung Ryu, KAIST, South Korea Richard P. Gabriel: poet, writer, computer scientist How a sidekick scripting language for Java, created at Netscape in a ten-day hack, ships first as a de facto Web standard and eventually becomes the world’s most widely used programming language. This paper tells the story of the creation, design, evolution, and standardization of the JavaScript language over the period of 1995–2015. But the story is not only about the technical details of the language. It is also the story of how people and organizations competed and collaborated to shape the JavaScript language which dominates the Web of 2020. CCS Concepts: • General and reference ! Computing standards, RFCs and guidelines; • Information systems ! World Wide Web; • Social and professional topics ! History of computing; History of programming languages; • Software and its engineering ! General programming languages; Scripting languages. Additional Key Words and Phrases: JavaScript, ECMAScript, Standards, Web browsers, Browser game theory, History of programming languages ACM Reference Format: Allen Wirfs-Brock and Brendan Eich. 2020. JavaScript: The First 20 Years. Proc. ACM Program. Lang. 4, HOPL (June 2020), 190 pages. https://doi.org/10.1145/3386327 1 INTRODUCTION In 2020, the World Wide Web is ubiquitous with over a billion websites accessible from billions of Web-connected devices. Each of those devices runs a Web browser or similar program which is able to process and display pages from those sites. The majority of those pages embed or load source code written in the JavaScript programming language.
    [Show full text]
  • Javascript: the Good Parts Vs. Javascript: the Definitive Guide CS252 – Advanced Programming Language Principles Prof
    JavaScript: The Good Parts vs. JavaScript: The Definitive Guide CS252 – Advanced Programming Language Principles Prof. Tom Austin, Fall 2014 JavaScript History of JavaScript In 1995, Netscape hired Brendan Eich to implement Scheme within the web browser. After a few meetings, Brendan Eich Scheme was deemed too weird… In 10 days, he wrote the initial version of JavaScript (then called Mocha) for Netscape 2.0 Beta. JavaScript • JavaScript looks superficially similar to languages like C++ and Java • Primarily client-side programming (i.e. code running in your browser & your machine), but some server-side variants – JVM: Rhino & Nashorn – Node.js • http://w3schools.com/js/default.asp JavaScript is multi-paradigm: • Imperative • Functional – "Scheme in C's clothing" • Object-oriented – Prototype-based Imperative JavaScript function addList(list) { var i, sum=0; for (i=0; i<list.length; i++){ sum += list[i]; } return sum; } Functional JavaScript var addList = function(list) { if (list.length === 0) { return 0; } return list[0] + addList(list.slice(1)); } Object-Oriented JavaScript function Adder (amount) { this.amount = amount; } Adder.prototype.add = function(x){ return this.amount + x; } var myAdder = new Adder(1); var y = myAdder.add(7); Extended JavaScript Examples (in-class) Introduction to Node.js Node.js • A JavaScript runtime and library designed for use outside the browser, based off of Google's V8 engine • npm: package manager for Node.js • http://nodejs.org/ myFile.txt This is my file. There are many like it, but this one is mine. File I/O in Node.js var fs = require('fs'); Callback fs.readFile('myFile.txt', function function(err,data) { if (err) throw err; console.log(""+data); }); console.log('all done'); Resulting Output all done This is my file.
    [Show full text]
  • Well, I'm Back: Choose Firefox Now, Or Later You Won't Get a Choice
    165 More Next Blog» Well, I'm Back Robert O'Callahan. Christian. Repatriate Kiwi. Mozilla hacker. FRIDAY, 8 AUGUST 2014 Choose Firefox Now, Or Later You Won't Get A Choice I know it's not the greatest marketing pitch, but it's the truth. Google is bent on establishing platform domination unlike anything we've ever s even from late-1990s Microsoft. Google controls Android, which is winning; Chro which is winning; and key Web properties in Search, Youtube, Gmail and Docs, are all winning. The potential for lock-in is vast and they're already exploiting it, f example by restricting certain Google Docs features (e.g. offline support) to Chro users, and by writing contracts with Android OEMs forcing them to make Chrom default browser. Other bad things are happening that I can't even talk about. Ind people and groups want to do the right thing but the corporation routes around th (E.g. PNaCl and Chromecast avoided Blink's Web standards commitments by d themselves not part of Blink.) If Google achieves a state where the Internet is re accessible through Chrome (or Android apps), that situation will be very difficult escape from, and it will give Google more power than any company has ever ha Microsoft and Apple will try to stop Google but even if they were to succeed, the only to replace one victor with another. So if you want an Internet --- which means, in many ways, a world --- that isn't co by Google, you must stop using Chrome now and encourage others to do the you don't, and Google wins, then in years to come you'll wish you had a choice a only yourself to blame for spurning it now.
    [Show full text]