NEW IN ES2016 JAVASCRIPT'S FIRST YEARLY RELEASE Brian

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Introduction to Ruby.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Haskell Chapter 7. Topics  Defining data types  Exporting types  Type parameters  Derived instances  Type synonyms  Either  Type classes  Not.
Library Builders map, set & weakmap __proto__ Proxies Symbols Sub-classable built-ins Scalable Apps let, const & block- scoped bindings Classes.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
COMP 14 Introduction to Programming Mr. Joshua Stough February 28, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
Jointly distributed Random variables
Chapter 10 Review: Matrix Algebra
Fruitful functions. Return values The built-in functions we have used, such as abs, pow, int, max, and range, have produced results. Calling each of these.
1 COMS 261 Computer Science I Title: Classes Date: November 7, 2005 Lecture Number: 28.
Functional principles for object-oriented
MATH 224 – Discrete Mathematics
CSE 1301 Lecture 11 Object Oriented Programming Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Example 1 The Distributive Property A. Find (y + 8)(y – 4). Vertical Method Multiply by –4. y + 8 (×) y – 4 –4y – 32–4(y + 8) = –4y – 32 Multiply by y.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Commutative and Associative Properties Return to table of contents.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
Introduction to TypeScript Sergey Barskiy Architect Level: Introductory.
GOAL: MULTIPLY TWO POLYNOMIALS TOGETHER USING THE DISTRIBUTIVE PROPERTY ELIGIBLE CONTENT: A Multiplying Polynomials.
Jianfeng Liu, eBay Justin Early, eclipse.org/vjet/
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
Splash Screen. Example 1 Write an Equation Given Roots (x – p)(x – q)=0Write the pattern. Simplify. Replace p with and q with –5. Use FOIL.
Equations of Lines and Planes
Chapter 5: Ball Worlds Features 2 classes, constant data fields, constructors, extension through inheritance, graphics.
DOM Animation Changing the DOM objects over time.
A Quick Introduction to d3.js & Reusable Charts Adam Pere Olin College, November 11 th 2014
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
CS305j Introduction to Computing Classes 1 Topic 23 Classes – Part I "A 'class' is where we teach an 'object' to behave." -Rich Pattis Based on slides.
New In ECMAScript 2016 & Beyond
Splash Screen. Then/Now You multiplied polynomials by monomials. Multiply binomials by using the FOIL method. Multiply polynomials by using the Distributive.
Types, Implementing, Extending, Interfaces, Superclasses, Subclasses, Casting, and Access Modifiers.
1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates.
Purpose of Operating System Monil Adhikari. Agenda Introduction Responsibilities of Operating System User Interfaces Command Line Interface Graphical.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "___________________" in Java Purpose –Reuse code –Modularize.
1 COMS 261 Computer Science I Title: Classes Date: November 9, 2005 Lecture Number: 29.
Text Overloading Techniques –Using CPP. 2 Overloading Techniques -Agenda 1.Introduction to Overloading 2.Function Overloading 3.Constructor Overloading.
This is our seminar JavaScript And DOM This is our seminar JavaScript And DOM.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
LESSON 3-2 ANGLES AND PARALLEL LINES. Concept Example 1 Use Corresponding Angles Postulate A. In the figure, m  11 = 51. Find m  15.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
EOC Practice #17 SPI EOC Practice #17 Determine the equation of a line and/or graph a linear equation.
Getting Started with Angular 2 and TypeScript Nebraska.Code() 2016 Spencer Schneidenbach Ryvit.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
Splash Screen Unit 8 Quadratic Expressions and Equations EQ: How do you use addition, subtraction, multiplication, and factoring of polynomials in order.
BELL RINGER. MULTIPLYING A MONOMIAL BY A POLYNOMIAL.
Splash Screen Unit 8 Quadratic Expressions and Equations EQ: How do you use addition, subtraction, multiplication, and factoring of polynomials in order.
Behavior trees & The C# programming language for Java programmers
Introduction to TypeScript
Game-Changing Features in ES2015
Use a graphing calculator to graph the following functions
Async or Parallel? No they aren’t the same thing!
Inheritance & Polymorphism
Displacement.
2.2 Defining Classes Part 2 academy.zariba.com.
Functions CIS 40 – Introduction to Programming in Python
Cancellation Primitives
12 Asynchronous Programming
What’s New in ChakraCore
Building responsive apps and sites with HTML5 web workers
Kinematics The Component Method.
JavaScript Reserved Words
Fundamentals of Functional Programming
CS5220 Advanced Topics in Web Programming More Node.js
SCOTT NO meeting Measurement
Find: AreaABCD [acres]
Final Exam Review 30 Multiple Choice Questions (Equally Weighted)
CS5220 Advanced Topics in Web Programming More Node.js
Threads and concurrency / Safety
Presentation transcript:

NEW IN ES2016 JAVASCRIPT'S FIRST YEARLY RELEASE Brian

AGENDA History Async Functions Observableas SIMD Decorators Value Types

ES2016 – BRING ON THE TRAIN MODEL Train leaves every year Mature proposals get on the train Multiple interoperable implementations required test262 collateral required Work on Github: ImageImage by speedemon08 CC BY NC SA 2.0

QUICK JAVASCRIPT FIX String#at "".length  2 ""[0]  " � " "".at(0)  ""

HOW DO WE… Return a single value synchronously? Functions! Return many values synchronously? Generator Functions! Return a single value asynchronously? Promise-returning function? Async Functions!

async function fetch(url) { return {... } } fetch('/tc39.json').then(parseJSON).then(f => { console.log(f.members.length); }); async function fetch(url) { let data = await $.get(url); return JSON.parse(data); } fetch('/tc39.json').then(f => { console.log(f.members.length); }); async function fetch(url) { try { let data = await $.get(url); return JSON.parse(data); } catch (e) { handleError(e); } fetch('/tc39.json').then(f => { console.log(f.members.length); }); ASYNC FUNCTIONS Built on Promises and Generators Callable like any function but: Returns a Promise `await` inside its body Similar to async/await in C# and Dart Implementations: Babel, Traceur, Regenerator class Image { async getData() {... } } let obj = { async fetch() {... } } async (a, b) => await a + await b;

HOW DO WE… Return a single value synchronously? Functions! Return many values synchronously? Generator Functions Return a single value asynchronously? Async Functions Return many values asynchronously? Observables!

// Observer let observer = { next(value) {/* got value */}, throw(error) { /* error getting values */ }, return() {/* no more values */} }; // Observable let observable = { subscribe(observer) {... } } OBSERVABLES Represents push-based (async) data sources DOM events! Lazy – no data emitted until a consumer wants it Built on the ES6 Generator interface Compositional: Chain map/filter/etc. operations Amenable to new syntax

// Observer let observer = { next(value) {/* got value */}, throw(error) { }, return() {/* no more values */} }; // Observable let d = new Observable( obs => { obs.next(1); obs.return();} ); d.subscribe(observer); OBSERVABLES Represents push-based (async) data sources DOM events! Lazy – no data emitted until a consumer wants it Built on the ES6 Generator interface Compositional: Chain map/filter/etc. operations Amenable to new syntax

// Observer let observer = function*() { while(1) log("Got " + (yield)); } // Observable let d = new Observable(obs => { obs.next(1); obs.return(); }); d.subscribe(observer()); // => "Got 1" OBSERVABLES Represents push-based (async) data sources DOM events! Lazy – no data emitted until a consumer wants it Built on the ES6 Generator interface Compositional: Chain map/filter/etc. operations Amenable to new syntax

// Observer let observer = prime(function*(){ while(1) log("Got " + (yield)); }) // Observable let d = new Observable(obs => { obs.next(1); obs.return(); }); d.subscribe(observer()); // => "Got 1" OBSERVABLES Represents push-based (async) data sources DOM events! Lazy – no data emitted until a consumer wants it Built on the ES6 Generator interface Compositional: Chain map/filter/etc. operations Amenable to new syntax

let d = new Observable(obs =>{ obs.next(1); obs.next(2); obs.return(); }); let d2 = d.map(n => n * 2); d2.subscribe({ next: log }); // => 2 // 4 OBSERVABLES Represents push-based (async) data sources DOM events! Lazy – no data emitted until a consumer wants it Built on the ES6 Generator interface Compositional: Chain map/filter/etc. operations Amenable to new syntax

let d = new Observable(obs =>{ obs.next(1); obs.next(2); obs.return(); }); let d2 = d.map(n => n * 2); d2.forEach(log); // => 2 // 4 OBSERVABLES Represents push-based (async) data sources DOM events! Lazy – no data emitted until a consumer wants it Built on the ES6 Generator interface Compositional: Chain map/filter/etc. operations Amenable to new syntax

let d = new Observable(obs =>{ obs.next(1); obs.next(2); obs.return(); }); let d2 = d.map(n => n * 2); for async (n of d2) { log(n); } // => 2 // 4 OBSERVABLES Represents push-based (async) data sources DOM events! Lazy – no data emitted until a consumer wants it Built on the ES6 Generator interface Compositional: Chain map/filter/etc. operations Amenable to new syntax

import {arrowKeys} from 'EventFilters'; let elem = $('document'); let keys = elem.listen('keypress'); let arrows = keys.filter(arrowKeys); arrowKeys.forEach(moveCharacter); OBSERVABLES Represents push-based (async) data sources DOM events! Lazy – no data emitted until a consumer wants it Built on the ES6 Generator interface Compositional: Chain map/filter/etc. operations Amenable to new syntax

QUICK JAVASCRIPT FIX Exponentiation Operator: Math.pow(10, 2)  10 ** 2

SIMD – SINGLE INSTRUCTION, MULTIPLE DATA Hardware instructions for number crunching Exploits data parallelism to perform multiple calculations simultaneously Benefits applications in fields like games, 3D graphics, audio/video processing, multimedia applications etc.

SIMD – SINGLE INSTRUCTION, MULTIPLE DATA Ax Bx Cx Dx Ay By Cy Dy Az Bz Cz Dz Scalar Operation Ax Bx Cx Dx Ay By Cy Dy Az Bz Cz Dz SIMD Operation of vector length 4 let a = [0, 1, 2, 3]; let b = [4, 5, 6, 7]; let c = [a[0] + b[0],a[1] + b[1],a[2] + b[2],a[3] + b[3]] let a = SIMD.int32x4(0, 1, 2, 3); let b = SIMD.int32x4(4, 5, 6, 7); let c = SIMD.int32x4.add(a, b);

SIMD – SINGLE INSTRUCTION, MULTIPLE DATA // normal sum function sum(list) { let sum = 0; let len = list.length; for (i = 0; i < len; i++){ sum += list[i]; } return sum; } // SIMD sum function sum(i32list) { let sum = SIMD.int32x4.zero(); let len = i32list.length; for (i = 0; i < len / 4; i++){ sum = SIMD.int32x4.add( sum, SIMD.Int32x4.load( i32list, i * 4 ) ); } return sum[0] + sum[1] + sum[2] + sum[3]; }

SIMD – SINGLE INSTRUCTION, MULTIPLE DATA DEMO

QUICK JAVASCRIPT FIX String#rpad & String#lpad "a".lpad(4)  " a";

class Person get name() { return this.first + this.last; } } function memoize(target, name, desc) { desc.set = v => setValue(target, name, v); desc.get = () => getFromCache(target, name)|| originalGet(target); } DECORATORS Modify behavior of things at design time Decoration of: Classes Properties Functions Parameters In the future, decoration of data properties Decorators are just functions! Early Implementation in TypeScript class Article comments; constructor() { /*... */ } clear() { this.comments.deleteAll()} class Author articles; constructor() { /*... */ }; class Comment { /*... */ }

// Example using factory let f32x4 = Float32x4(0, 1, 2, 3); let int8 = Int8(254); // Example using literal suffixes let i64 = 0L; // Int64 let ui64 = 0UL;// Uint64 let f32 = 0f; // Float32 let bignum = 0n; // Bignum let dec = 0m; // Decimal VALUE TYPES (work in progress) New Primitive Types: Int64/Uint64 Bignum Decimal Complex Rational SIMD types TypedArray types Literal Suffixes! Benefits: Serialize across iframes Immutable === compares by value

// Measures.js export let Yard = ValueType(Symbol("Yard"), Float64); export let Foot = ValueType(Symbol("Feet"), Float64); // Define literal suffixes (WIP!) LiteralSuffixTable.ya = Yard; LiteralSuffixTable.ft = Feet; VALUE TYPES (work in progress) Custom Primitive Types! Compose new primitive types from existing ones using the ValueType factory Assign custom suffixes Overload operators

// Measures.js function addYandF(y, f) { return Foot(y * 3 + f) } function addFandY(f, y) { return addCandF(y, f) } Reflect.defineOperator('+', addYandF, Yard, Foot); Reflect.defineOperator('+', addFandY, Foot, Yard); VALUE TYPES (work in progress) Custom Primitive Types! Compose new primitive types from existing ones using the ValueType factory Assign custom suffixes Overload operators

Import {Yard, Feet} from "Measures.js" let pos = 87ya; let pass = 20ft; let newPos = pos + pass; // Foot(281) // css math? 20em + 10px; // vector math? let v1 = Vector(1, 2); let v2 = Vector(3, 4); v1 + v2; // Vector(4, 6) VALUE TYPES (work in progress) Custom Primitive Types! Compose new primitive types from existing ones using the ValueType factory Assign custom suffixes Overload operators

Thank You! Github:

EASY WINS Exponentiation Operator: Math.pow(10, 2)  10 ** 2 String#rpad & String#lpad "a".lpad(4)  " a"; String#at ""[0]  " � " "".at(0)  ""

async function* readLines(path) { let file = await fileOpen(path); try { while (!file.EOF) yield file.readLine(); } finally { await file.close(); } ASYNC GENERATORS Builds on Promises, Generators, and Async Functions `await` and `yield` `await` behaves like Async Functions `yield` behaves like Generator Functions Returns an Iterator-like object Has.next,.throw, and.return But each returns Promise rather than IterationResult Includes new Async for-of loop

let iter = readLines('/foo.txt'); function read() { let p = iter.next(); p.then(result => { if(result.done) return; print(result.value); read(); }); } read(); ASYNC GENERATORS Builds on Promises, Generators, and Async Functions `await` and `yield` `await` behaves like Async Functions `yield` behaves like Generator Functions Returns an Iterator-like object Has.next,.throw, and.return But each returns Promise rather than IterationResult Includes new Async for-of loop

for async (let line of readLines('foo.txt') ) { print(line); } ASYNC GENERATORS Builds on Promises, Generators, and Async Functions `await` and `yield` `await` behaves like Async Functions `yield` behaves like Generator Functions Returns an Iterator-like object Has.next,.throw, and.return But each returns Promise rather than IterationResult Includes new Async for-of loop