KEMBAR78
ECMAScript 5: Новое в JavaScript | PPT
ECMAScript 5: Новое в JavaScript Юрій Чайковський [email_address]
Syntax Reserved   words   var  label = { class : " active " } Comma var  fibonacci = [0, 1, 2, 3, 5, ]; Line breaks var   literal  = "Line breaks \ is standardized";
Arrays Iterations  forEach(), every(), some(), map(), filter(), reduce(), reduceRight(),  Search indexOf(), lastIndexOf() Type check fibonacci.isArray() === true ;
JSON var  event = { title : " HTML5Camp  ", date  : new Date(" 2011-03-28T10:00:00.000Z "),  } JSON.stringify(value, replacer, space) var  str = JSON.stringify(event) ; {"title":"HTML5Camp","date":"2011-03-28T10:00:00.000Z"} JSON.parse(string,  reviver) JSON.parse(str, function(key, value){ if (key == "title"){ return  value.trim(); } });
Strict mode "use strict"; location = " http://www.microsoft.com "; var  person = {"name" : "Yura", "name" : "Chaikovsky"}; var  geval = eval; with, arguments.caller, arguments.callee ( function (){...}).call( null ); ( function (){ return  !this; })(); Function.prototype.bind(thisArg, arg1, arg2....)
Objects: Point function  Point(x, y) {   this .x = +x;    this .y = +y;  } var  pt =  new  Point(3,5); pt.x = 'foo';
Objects: Creating Object.create( p ,{ ( n : attrs )* })      .defineProperty( o , n , attrs )   .defineProperties( o ,{ ( n : attrs )* })   .getOwnPropertyNames( o )  ->   names   .getOwnPropertyDescriptor( o , n )  ->   attrs attrs  ::= {  value: v ,    writable: b ,         enumerable: b ,    configurable: b   } |   { get: f()->v ,  set: f(v) ,       enumerable: b ,   configurable: b  }
Objects: New Point function  Point(x, y) {   return   Object.freeze ({   x: +x,   y: +y   }); } // (new Point(3,4)  instanceof  Point) === false
Objects: New Point function  Point(x, y) {   return   Object.freeze ({   x: +x,   y: +y   }); } // (new Point(3,4)  instanceof  Point) === false function  Point(x, y) {   return  Object.freeze(   Object.create (Point.prototype, {   x: { value: +x, enumerable: true },   y: { value: +y, enumerable: true }   })); }
Objects: Accessor (getter/setter)  Old school... var  evnt = ( function (){ var  eventType = " barcamp "; return  { type :  function (tp){ if (typeof tp != " undefined "){ //setter... eventType = tp; }else{ //getter... return  eventType; } } }; })();
Objects: Creating Object.create( p ,{ ( n : attrs )* })      .defineProperty( o , n , attrs )   .defineProperties( o ,{ ( n : attrs )* })   .getOwnPropertyNames( o )  ->   names   .getOwnPropertyDescriptor( o , n )  ->   attrs attrs  ::= { value: v ,    writable: b ,         enumerable: b ,    configurable: b  } |   {  get: f()->v ,  set: f(v) ,       enumerable: b ,   configurable: b   }
Objects: Accessor (getter/setter)  Brand new... var  evnt = { eventType : "barcamp", get  type(){ //getter... return  evnt.eventType; }, set  type(tp){ //setter... evnt.eventType = tp; } };
Objects: Accessor (getter/setter)  or... var  evnt = Object.defineProperties({},   {  'typeName' : { value : "barcamp",  },   'type' : {   get : function() { return …; },   set : function(tp) { … },  } });
Objects:  Restrictions   Object.preventExtensions( obj ) Object.isExtensible( obj ) Object.seal( obj ) Object.isSealed( obj ) Object.freeze( obj ) Object.isFrozen( obj )
References Mark Miller http://www.youtube.com/watch?v=Kq4FpMe6cRs Douglas Crockford http://www.slideshare.net/douglascrockford/newandimproved Ilia Kantor http://www.youtube.com/watch?v=082iuEKV72c John Resig http://ejohn.org/blog/ecmascript-5-objects-and-properties/ http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ David Flanagan http://davidflanagan.com/Talks/es5/slides.html

ECMAScript 5: Новое в JavaScript

  • 1.
    ECMAScript 5: Новоев JavaScript Юрій Чайковський [email_address]
  • 2.
    Syntax Reserved words var label = { class : " active " } Comma var fibonacci = [0, 1, 2, 3, 5, ]; Line breaks var literal = "Line breaks \ is standardized";
  • 3.
    Arrays Iterations forEach(), every(), some(), map(), filter(), reduce(), reduceRight(), Search indexOf(), lastIndexOf() Type check fibonacci.isArray() === true ;
  • 4.
    JSON var event = { title : " HTML5Camp ", date : new Date(" 2011-03-28T10:00:00.000Z "), } JSON.stringify(value, replacer, space) var str = JSON.stringify(event) ; {"title":"HTML5Camp","date":"2011-03-28T10:00:00.000Z"} JSON.parse(string, reviver) JSON.parse(str, function(key, value){ if (key == "title"){ return value.trim(); } });
  • 5.
    Strict mode "usestrict"; location = " http://www.microsoft.com "; var person = {"name" : "Yura", "name" : "Chaikovsky"}; var geval = eval; with, arguments.caller, arguments.callee ( function (){...}).call( null ); ( function (){ return !this; })(); Function.prototype.bind(thisArg, arg1, arg2....)
  • 6.
    Objects: Point function Point(x, y) {   this .x = +x; this .y = +y; } var pt = new Point(3,5); pt.x = 'foo';
  • 7.
    Objects: Creating Object.create(p ,{ ( n : attrs )* })   .defineProperty( o , n , attrs ) .defineProperties( o ,{ ( n : attrs )* }) .getOwnPropertyNames( o ) -> names .getOwnPropertyDescriptor( o , n ) -> attrs attrs ::= { value: v , writable: b ,       enumerable: b , configurable: b } | { get: f()->v , set: f(v) ,      enumerable: b , configurable: b }
  • 8.
    Objects: New Pointfunction Point(x, y) { return Object.freeze ({ x: +x, y: +y }); } // (new Point(3,4) instanceof Point) === false
  • 9.
    Objects: New Pointfunction Point(x, y) { return Object.freeze ({ x: +x, y: +y }); } // (new Point(3,4) instanceof Point) === false function Point(x, y) { return Object.freeze( Object.create (Point.prototype, { x: { value: +x, enumerable: true }, y: { value: +y, enumerable: true } })); }
  • 10.
    Objects: Accessor (getter/setter) Old school... var evnt = ( function (){ var eventType = " barcamp "; return { type : function (tp){ if (typeof tp != " undefined "){ //setter... eventType = tp; }else{ //getter... return eventType; } } }; })();
  • 11.
    Objects: Creating Object.create(p ,{ ( n : attrs )* })   .defineProperty( o , n , attrs ) .defineProperties( o ,{ ( n : attrs )* }) .getOwnPropertyNames( o ) -> names .getOwnPropertyDescriptor( o , n ) -> attrs attrs ::= { value: v , writable: b ,       enumerable: b , configurable: b } | { get: f()->v , set: f(v) ,      enumerable: b , configurable: b }
  • 12.
    Objects: Accessor (getter/setter) Brand new... var evnt = { eventType : "barcamp", get type(){ //getter... return evnt.eventType; }, set type(tp){ //setter... evnt.eventType = tp; } };
  • 13.
    Objects: Accessor (getter/setter) or... var evnt = Object.defineProperties({}, { 'typeName' : { value : "barcamp", }, 'type' : { get : function() { return …; }, set : function(tp) { … }, } });
  • 14.
    Objects: Restrictions Object.preventExtensions( obj ) Object.isExtensible( obj ) Object.seal( obj ) Object.isSealed( obj ) Object.freeze( obj ) Object.isFrozen( obj )
  • 15.
    References Mark Millerhttp://www.youtube.com/watch?v=Kq4FpMe6cRs Douglas Crockford http://www.slideshare.net/douglascrockford/newandimproved Ilia Kantor http://www.youtube.com/watch?v=082iuEKV72c John Resig http://ejohn.org/blog/ecmascript-5-objects-and-properties/ http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ David Flanagan http://davidflanagan.com/Talks/es5/slides.html