MASTERING NAMESPACES! Илья Кантор EcmaScript 5.

Slides:



Advertisements
Similar presentations
Chapter 6: JavaScript Functions 6.1 The Purpose of Functions 6.2 Defining JavaScript Functions 6.3 Using JavaScript Functions 6.4 Global Functions and.
Advertisements

Web Application Development Muhammad Ali Versonic Pte Asher Imtiaz Forman Christian College.
Strings in Java 1. strings in java are handled by two classes String &
A Crash Course Python. Python? Isn’t that a snake? Yes, but it is also a...
ECMAScript 5: The New Parts Level 7. Complete implementations of ECMAScript, Fifth Edition, are now in the best web browsers. Including IE10.
By: Daniel Henneberger.  Introduction  Data Types  Flow Control  Inheritance/Built-in Functions  User defined types, Generics  Arrays  Function.
Starting Out with C++, 3 rd Edition 1 Chapter 16 – Exceptions, Templates, and the Standard Template Library (STL) Exceptions are used to signal errors.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Taking JavaScript Seriously IS NOT THE WORST IDEA.
Lesson 4 Cell Reference Formulas. Working with Cell References continued… Relative Cell Reference A relative cell reference means that the cell value.
Microsoft SQL Server 2008 Installation Guide Omer Alrwais.
MongoDB An introduction. What is MongoDB? The name Mongo is derived from Humongous To say that MongoDB can handle a humongous amount of data Document.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Chapter 3 : Processing on the Front End JavaScript Technically its name is ECMA-262, which refers to the international standard which defines it. The standard.
Web Application Development Muhammad Ali.  The Problem  Changing the Content of Page Dynamically  Efficient Utilization of Resources.
Javascript & DOM. Javascript – main properties is a lightweight scripting language (language used to control the browser) that is run on the client-side.
M IMIC : Computing Models for Opaque Code Stefan Heule, Manu Sridharan, Satish Chandra Stanford University, Samsung Research America September 4, 2015;
JavaScript: The Language Andrew Miadowicz Program Manager DEV307.
Copyright By Free for non-commercial use. Editable provided that the copyright claim is included.
Javascript. Javascript Tools Javascript Console Javascript Console Debugger Debugger DOM Inspector DOM Inspector.
Introduction to JavaScript Gordon Tian
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Lecture 9 The Basics of JavaScript Boriana Koleva Room: C54
JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-
Changes to JavaScript, Part 1: EcmaScript 5 Mark S. Miller, Waldemar Horwat, Mike Samuel Your EcmaScript committee representatives.
Javascript. What is JavaScript? Scripting (interpreted) language designed for the web Beware: JavaScript is case sensitive.
JavaScript Best Practices Learn How to Write Better Quality JavaScript Software University Technical Trainers SoftUni Team.
Martin Kruliš by Martin Kruliš (v1.0)1.
Events DOM Event Model. HTML Events "on" + event name attribute value is javascript javascript runs 1st return false to STOP browser event (if any)
ECMAScript 3.1 Object Model Allen Wirfs-Brock Microsoft.
JavaScript for.Net Developers The things you need to know Pavel Kolev
10 – Java Script (3) Informatics Department Parahyangan Catholic University.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Objects.
JavaScript Assignment Statements Expressions Global Functions CST 200 JavaScript.
Introduction to Web Frontend Development with JavaScript.
Associative Arrays and Objects Associative Arrays, Objects Svetlin Nakov Technical Trainer Software University
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
CIS 228 The Internet 11/17/11 Of Timers and Cookies.
Developer Exam Preparation Thom Robbins Bryan Soltis
1 Объектно-ориентированное программирование на JavaScript Преподаватель: Танаков А.И. Подготовил Д. А. Быстров.
Solving Inequalities Using Addition or Subtraction Honors Math – Grade 8.
Martin Kruliš by Martin Kruliš (v1.1)1.
JavaScript Best Practices Learn How to Write Better Quality JavaScript Software University Technical Trainers SoftUni Team.
Autodesk® PLM 360 Developer's Delight:
JavaScript: Good Practices
Habits of Highly Effective JavaScript Developers
Chapter 4 Client-Side Programming: the JavaScript Language
CS5220 Advanced Topics in Web Programming JavaScript and jQuery
6.001 SICP Variations on a Scheme
Modern JavaScript Luke Hoban Program Manager — JavaScript
Juriy Bura
Functions Declarations, Function Expressions and IIFEs
البرمجة بلغة الفيجول بيسك ستوديو
البرمجة بلغة فيجول بيسك ستوديو
JavaScript: The Language
Modern JavaScript Develop And Design
CS5220 Advanced Topics in Web Programming JavaScript Basics
University of Kurdistan
The Internet 11/15/11 Handling Data in JavaScript
CS5220 Advanced Topics in Web Programming Node.js Basics
CS3220 Web and Internet Programming JavaScript Basics
Past, current and Future
Introducing JavaScript
Chengyu Sun California State University, Los Angeles
Javascript & DOM.
Chapter 4 - JavaScript Events, Objects, & Functions
CS3220 Web and Internet Programming JavaScript Basics
Chengyu Sun California State University, Los Angeles
Title: Date: Cause: Event: Effect: Title: Title: Title: Date: Cause:
Murach's JavaScript and jQuery (3rd Ed.)
Presentation transcript:

MASTERING NAMESPACES! Илья Кантор EcmaScript 5

История

1997 ECMA st edition 1999 ECMA rd edition 2009 ECMA th edition ??? 2001 Compact Profile 2004 E4X var user = alert( == ) — ECMA th ed. — ECMA-262 Harmony

Что нового? ECMA th edition

Багфиксы ECMA th edition

obj = { class: 'Menu' } ES3: ошибка ES5: ok

function test(str) { var re = /ok/g alert( re.test(str) ) } test("ok") // true // ES3: false, ES5: true

alert( parseInt("010") == parseFloat("010") ) ES3: false ES5: true

var obj = { a: 1, b: 2, } var arr [ 1, 2, 3, ] ES3: error ES5: ok

МетаСвойства

writable = false obj = { class: 'Menu' } obj.class = 'Bird‘ => obj.class == ‘Menu’

configurable = false obj = { class: 'Menu' } => obj.class == ‘Menu’ delete obj.class

enumerable = false Object.prototype.each =... for(prop in {}) { // без свойства ‘each’ }

Объявление Object.defineProperty({}, "class", { value: "Menu", writable: false, configurable: false, enumerable: true }) => { “class” : “Menu” } property descriptor

Объявление Object.defineProperties({}, { class: { value: "Menu", writable: false, configurable: false }, height: { value: 200, configurable: false } }) => { “class” : “Menu”, “height”: 200 }

Закрытие объекта var user = { name: "Вася", /*... */ } Object.preventExtensions(user) Object.seal(user) Object.freeze(user) user.a = 5 // Нельзя добавлять свойства delete user.name // Нельзя удалять свойства user.name = 'Петя' // Нельзя менять свойства

Наследование animal = { canWalk: true } rabbit = Object.create(animal, { canRun: { value: true } }) alert(rabbit.canWalk) // true Object.getPrototypeOf(rabbit) == animal // true

Наследование rabbit = Object.create(animal, { canRun: { value: true } }) bird = Object.create(Object.getPrototypeOf(rabbit), { canFly: { value: true } })

Геттеры и Сеттеры user = Object.defineProperty({}, "fullName", { get: function() { return this.firstName+' '+this.lastName }, set: function(value) { var s = value.trim().split(/\s+/, 2) this.firstName = s[0]; this.lastName = s[1] } }) user.fullName = "Вася Пупкин" alert(user.lastName) // Пупкин

Геттеры и Сеттеры var user = { get fullName () { return this.firstName+' '+this.lastName }, set fullName (value) { var s = value.trim().split(/\s+/, 2) this.firstName = s[0]; this.lastName = s[1] } user.fullName = "Вася Пупкин" alert(user.lastName) // Пупкин

JSON

event = { title: "Conference", date: “today" } str = JSON.stringify(event) {"title":"Conference","date":"today"} event =

JSON – любые объекты function Room(number) { this.toJSON = function() { return number } event = { title: "Conference", date: new Date(), room: new Room(22) } JSON.stringify(event) {"title":"Conference","date":" T09:12:06.836Z","room":22}

JSON – любые объекты function Room(number) { this.toJSON = function() { return number } event = { title: "Conference", date: new Date(), Date.prototype.toJSON room: new Room(22) } JSON.stringify(event) {"title":"Conference","date":" T09:12:06.836Z","room":22}

JSON.stringify(str, whitelist) event = { title: "Conference", date: new Date(), domElement: document.body } JSON.stringify(event, ["title", "date"]) => {"title":"Conference","date":" T09:44:13.419Z"} JSON.stringify(event) => TypeError: Converting circular structure to JSON

JSON.stringify(str, replacer) event = { title: "Conference", date: new Date(), domElement: document.body } JSON.stringify(event, function(key, value) { return value.nodeName ? undefined : value }) => {"title":"Conference","date":" T09:44:13.419Z"}

JSON.parse(str) str = '{"title":"Conference", \ "date":" T09:44:13.419Z"}' event = JSON.parse(str) пробелы

JSON.parse(str) str = '{"title":"Conference", \ "date":" T09:44:13.419Z"}' event = JSON.parse(str) event.date.getDay() => TypeError: no method 'getDay'

JSON.parse(str, reviver) str = '{"title":"Conference", \ "date":" T09:44:13.419Z"}' event = JSON.parse(str, function(key, value) { if (key == 'date') { return new Date(value) } return value }) event.date.getDay() => 2

bind

bind(this) function Button(elem) { this.sayHi = function() { alert('Hi') } elem.onclick = function() { this.sayHi() }.bind(this) }

bind(this, args) function Button(elem) { this.say = function(phrase) { alert(phrase) } elem.onclick = function(event, phrase) { this.say(phrase) }.bind(this, 'Hi')

Strict mode

"use strict"... code... use strict

function F() { "use strict" this.method = function() { // strict mode inherited } use strict

alert(010) // SyntaxError (octal literals deprecated) use strict a = 5 // ReferenceError (undeclared a) obj.notWritable =... // TypeError delete obj.notConfigurable // TypeError eval("var a = 5") alert(a) // ReferenceError (undeclared a) arguments.callee // TypeError arguments.caller // TypeError (function() { alert(this) // undefined вместо window })() with(..) // SyntaxError, 'with' statement

Функции, которые давно ждали Object.keys(obj) "String".trim() Array.isArray(arr) [...].indexOf / lastIndexOf [...].forEach [...].map [...].filter [...].reduce / reduceRight

Harmony

__noSuchMethod__ Proxy.create let block_scoped = "yay!" const REALLY = "srsly" #(x) { x * x } if x > z return "без скобок" module Iter = return [i * i for i in range(n)] function printf(format,...args) ek_scoped = "yay!" consEALLY = "srsly" It’s all real