javascript the good parts vs javascript the definitive
play

JavaScript: The Good Parts vs. JavaScript: The Definitive Guide CS - PowerPoint PPT Presentation

JavaScript: The Good Parts vs. JavaScript: The Definitive Guide CS 252: Advanced Programming Language Principles Introduction to JavaScript Prof. Tom Austin San Jos State University History of JavaScript In 1995, Netscape hired Brendan


  1. JavaScript: The Good Parts vs. JavaScript: The Definitive Guide

  2. CS 252: Advanced Programming Language Principles Introduction to JavaScript Prof. Tom Austin San José State University

  3. History of JavaScript In 1995, Netscape hired Brendan Eich to implement Scheme within the web browser. Brendan Eich After a few meetings, Scheme was deemed too weird… In 10 days , he wrote the initial version of JavaScript (then called Mocha) for Netscape 2.0 Beta.

  4. JavaScript • Syntax similar to Java • Client-side programming – Code runs on your machine • Server-side variants exist – JVM: Rhino & Nashorn – Node.js • http://w3schools.com/js/default.asp

  5. JavaScript is multi-paradigm : • Imperative • Functional – "Scheme in C's clothing" • Object-oriented – Prototype-based

  6. Imperative JavaScript function addList(list) { var i, sum=0; for (i=0; i<list.length; i++){ sum += list[i]; } return sum; }

  7. Functional JavaScript var addList = function(list) { if (list.length === 0) { return 0; } return list[0] + addList(list.slice(1)); }

  8. 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);

  9. Extended JavaScript Examples (in-class)

  10. Introduction to Node.js

  11. 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/

  12. myFile.txt This is my file. There are many like it, but this one is mine.

  13. 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');

  14. Resulting Output all done This is my file. There are many like it, but this one is mine.

  15. Synchronous File IO in Node var data = fs.readFile Sync ( './myFile.txt'); console.log(data.toString()); console.log('all done');

  16. Lab: Intro to JavaScript Today's lab explores both the functional and object-oriented aspects of JavaScript. See Canvas for details.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend