Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
var firstName = Symbol();
var person =...
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
var firstName = Symbol("first name");
...
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
var symbol = Symbol("test symbol");
co...
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
// Option 1:
var firstName = Symbol("f...
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
class Person{
constructor(name){
this....
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
http://www.2ality.com/
Understanding E...
© 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
eyalvardi.wordpress.com
Upcoming SlideShare
Loading in …5
×

Symbols in ECMAScript 6.0

976 views

Published on

Symbols in ECMAScript 6.0

Published in: Software
  • Be the first to comment

Symbols in ECMAScript 6.0

  1. 1. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  2. 2. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com var firstName = Symbol(); var person = {}; person[firstName] = "Eyal"; console.log( person[firstName] ); // "Eyal"
  3. 3. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com var firstName = Symbol("first name"); var person = {}; person[firstName] = "Eyal"; console.log("first name" in person); // false console.log(person[firstName]); // "Eyal" console.log(firstName); // "Symbol(first name)" The Symbol function accepts an optional argument that is the description of the symbol.
  4. 4. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com var symbol = Symbol("test symbol"); console.log( typeof symbol ); // "symbol"
  5. 5. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com // Option 1: var firstName = Symbol("first name"); var person = {}; person[firstName] = "Eyal"; // Option 2: var person = { [firstName] : "Eyal" }; // Option 3: // make the property read only Object.defineProperty( person, firstName, { writable: false } );
  6. 6. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  7. 7. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  8. 8. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  9. 9. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com class Person{ constructor(name){ this.name = name; } [Symbol.toStringTag](){ return "Person"; } toString(){ return this.name; } } var me = new Person("Eyal Vardi"); console.log(me.toString()); // Eyal Vardi console.log(Object.prototype.toString.call(me)); // Person
  10. 10. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com http://www.2ality.com/ Understanding ECMAScript 6 http://ecmascript6.org/ A Few New Things Coming To JavaScript HARMONY OF DREAMS COME TRUE Harmony specification_drafts
  11. 11. © 2015 Eyal Vardi. All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com eyalvardi.wordpress.com

×