• Like
new JavaScript
Upcoming SlideShare
Loading in...5
×

new JavaScript

  • 212 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
212
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
4
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. new JavaScript;
  • 2. Самый популярный
  • 3. №1 на GitHub
  • 4. загадочный субъективный параметр время, затраченное на поиск официальной версии логотипа
  • 5. Самый доступный
  • 6. В каждом браузере
  • 7. ...и не только
  • 8. Самый простой
  • 9. {}
  • 10. f()
  • 11. В JavaScript нет● паттерн-матчинга● лист компрехеншнов● континьюэйшнов● корутин● монад● языковой поддержки модулей● огромной стандартной библиотеки● классов с названиями типа SQLIntegrityConstraintViolationException● и вообще классов
  • 12. f() {}
  • 13. f() <: {}
  • 14. Function — это объектObject — это функция
  • 15. {}
  • 16. two = 2;yes = true;obj = {};str = "hello";arr = [];nop = function () {};rex = /dog/;now = new Date;
  • 17. two = 2;yes = true;obj = {};str = "hello";arr = [];nop = function () {};rex = /dog/;now = new Date;
  • 18. new
  • 19. > typeof Date"function"> Date()"Wed Oct 17 2012 18:13:52GMT+0700 (NOVT)"> new Date()Wed Oct 17 2012 18:13:54GMT+0700 (NOVT)
  • 20. > typeof Date()"string"> typeof (new Date())"object"
  • 21. object.constructor
  • 22. two.constructor == Number;yes.constructor == Boolean;obj.constructor == Object;str.constructor == String;arr.constructor == Array;nop.constructor == Function;rex.constructor == RegExp;now.constructor == Date;
  • 23. function Person(first, last) { this.firstName = first; this.lastName = last;}var bob = new Person(Bob);bob.firstName; // Bob
  • 24. > bob.constructor === Persontrue> bob instanceof Persontrue
  • 25. > empty = {}▸ Object> empty.constructorfunction Object() { ... }> empty.toString()"[object Object]"
  • 26. > empty = {}▾ Object ▾ __proto__: Object ... ▸ constructor: function... ▸ isPrototypeOf: function... ▸ toString: function... ▸ valueOf: function... ...
  • 27. null
  • 28. > zen = Object.create(null)▾ Object No Properties> zen instanceof Objectfalse> typeof zen"object"
  • 29. person = Object.create(null);person.fullName = function () { return this.firstName + + this.lastName;};man = Object.create(person);man.sex = male;
  • 30. bob = Object.create(man);bob.firstName = bob;bob.lastName = smith;bob.sex; // malebob.fullName(); // bob smith
  • 31. > bob▾ Object firstName: "bob" lastName: "smith" ▾ __proto__: Object sex: "male" ▾ __proto__: Object ▸ fullName: function...
  • 32. nullpersonfullName function () { ... }mansex "male"bobfirstName "bob"lastName "smith"
  • 33. function Person(first, last) { this.firstName = first; this.lastName = last;}var bob = new Person(Bob);bob.firstName; // Bob
  • 34. function Person(first, last) { this.firstName = first; this.lastName = last; this.fullName = function () { return this.firstName + + this.lastName; }}
  • 35. alice firstName "alice" lastName "jones" fullName function () ...bobfirstName "bob"lastName "smith"fullName function () ...
  • 36. Constructor.prototype
  • 37. function Person(first, last) { this.firstName = first; this.lastName = last;}Person.prototype.fullName =function () { return this.firstName + + this.lastName;}
  • 38. Person.prototype fullName function () ... alice firstName "alice" lastName "jones"bobfirstName "bob"lastName "smith"
  • 39. f()
  • 40. Объекты первого класса
  • 41. function foo() { return FOO;}
  • 42. var bar = foo;bar(); // FOO
  • 43. function baz(f) { return f();}baz(foo); // FOO
  • 44. function quux() { return foo;}quux()(); // FOO
  • 45. var code = return "FOO"var foo = new Function(code);foo(); // FOO
  • 46. Область видимости переменных
  • 47. var
  • 48. function fred(x) { var a = 10; return a * x;}var a = 3;fred(5); // 50console.log(a); // 3
  • 49. function fred(x) { /*no var*/ a = 10; return a * x;}var a = 3;fred(5); // 50console.log(a); // 10
  • 50. this
  • 51. Person.prototype.fullName =function () { return this.firstName + + this.lastName;}bob = new Person(bob);bob.fullName();// bob undefined
  • 52. xavier = { firstName: xavier, lastName: sanchez};xavier.fullName(); // error!
  • 53. xavier.fullName = Person.prototype.fullName;xavier.fullName(); // xavier sanchez
  • 54. Person.prototype .fullName .call(xavier); // xavier sanchez
  • 55. that
  • 56. function Logger(s) { s.on(data, function (d) { this.log(d); });}Logger.prototype.log =function (data) { console.log(new Date, data);}
  • 57. function Logger(s) { s.on(data, function (d) { this.log(d); });}
  • 58. function Logger(s) { var that = this; s.on(data, function (d) { that.log(d); });}
  • 59. function Logger(s) { s.on(data, Logger.prototype .log.bind(this));}
  • 60. jifasnif @stevebest https://github.com/stevebest