• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
new JavaScript
 

new JavaScript

on

  • 364 views

 

Statistics

Views

Total Views
364
Views on SlideShare
364
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    new JavaScript new JavaScript Presentation Transcript

    • new JavaScript;
    • Самый популярный
    • №1 на GitHub
    • загадочный субъективный параметр время, затраченное на поиск официальной версии логотипа
    • Самый доступный
    • В каждом браузере
    • ...и не только
    • Самый простой
    • {}
    • f()
    • В JavaScript нет● паттерн-матчинга● лист компрехеншнов● континьюэйшнов● корутин● монад● языковой поддержки модулей● огромной стандартной библиотеки● классов с названиями типа SQLIntegrityConstraintViolationException● и вообще классов
    • f() {}
    • f() <: {}
    • Function — это объектObject — это функция
    • {}
    • two = 2;yes = true;obj = {};str = "hello";arr = [];nop = function () {};rex = /dog/;now = new Date;
    • two = 2;yes = true;obj = {};str = "hello";arr = [];nop = function () {};rex = /dog/;now = new Date;
    • new
    • > typeof Date"function"> Date()"Wed Oct 17 2012 18:13:52GMT+0700 (NOVT)"> new Date()Wed Oct 17 2012 18:13:54GMT+0700 (NOVT)
    • > typeof Date()"string"> typeof (new Date())"object"
    • object.constructor
    • two.constructor == Number;yes.constructor == Boolean;obj.constructor == Object;str.constructor == String;arr.constructor == Array;nop.constructor == Function;rex.constructor == RegExp;now.constructor == Date;
    • function Person(first, last) { this.firstName = first; this.lastName = last;}var bob = new Person(Bob);bob.firstName; // Bob
    • > bob.constructor === Persontrue> bob instanceof Persontrue
    • > empty = {}▸ Object> empty.constructorfunction Object() { ... }> empty.toString()"[object Object]"
    • > empty = {}▾ Object ▾ __proto__: Object ... ▸ constructor: function... ▸ isPrototypeOf: function... ▸ toString: function... ▸ valueOf: function... ...
    • null
    • > zen = Object.create(null)▾ Object No Properties> zen instanceof Objectfalse> typeof zen"object"
    • person = Object.create(null);person.fullName = function () { return this.firstName + + this.lastName;};man = Object.create(person);man.sex = male;
    • bob = Object.create(man);bob.firstName = bob;bob.lastName = smith;bob.sex; // malebob.fullName(); // bob smith
    • > bob▾ Object firstName: "bob" lastName: "smith" ▾ __proto__: Object sex: "male" ▾ __proto__: Object ▸ fullName: function...
    • nullpersonfullName function () { ... }mansex "male"bobfirstName "bob"lastName "smith"
    • function Person(first, last) { this.firstName = first; this.lastName = last;}var bob = new Person(Bob);bob.firstName; // Bob
    • function Person(first, last) { this.firstName = first; this.lastName = last; this.fullName = function () { return this.firstName + + this.lastName; }}
    • alice firstName "alice" lastName "jones" fullName function () ...bobfirstName "bob"lastName "smith"fullName function () ...
    • Constructor.prototype
    • function Person(first, last) { this.firstName = first; this.lastName = last;}Person.prototype.fullName =function () { return this.firstName + + this.lastName;}
    • Person.prototype fullName function () ... alice firstName "alice" lastName "jones"bobfirstName "bob"lastName "smith"
    • f()
    • Объекты первого класса
    • function foo() { return FOO;}
    • var bar = foo;bar(); // FOO
    • function baz(f) { return f();}baz(foo); // FOO
    • function quux() { return foo;}quux()(); // FOO
    • var code = return "FOO"var foo = new Function(code);foo(); // FOO
    • Область видимости переменных
    • var
    • function fred(x) { var a = 10; return a * x;}var a = 3;fred(5); // 50console.log(a); // 3
    • function fred(x) { /*no var*/ a = 10; return a * x;}var a = 3;fred(5); // 50console.log(a); // 10
    • this
    • Person.prototype.fullName =function () { return this.firstName + + this.lastName;}bob = new Person(bob);bob.fullName();// bob undefined
    • xavier = { firstName: xavier, lastName: sanchez};xavier.fullName(); // error!
    • xavier.fullName = Person.prototype.fullName;xavier.fullName(); // xavier sanchez
    • Person.prototype .fullName .call(xavier); // xavier sanchez
    • that
    • function Logger(s) { s.on(data, function (d) { this.log(d); });}Logger.prototype.log =function (data) { console.log(new Date, data);}
    • function Logger(s) { s.on(data, function (d) { this.log(d); });}
    • function Logger(s) { var that = this; s.on(data, function (d) { that.log(d); });}
    • function Logger(s) { s.on(data, Logger.prototype .log.bind(this));}
    • jifasnif @stevebest https://github.com/stevebest