tern
play

Tern http://ternjs.net 1 // Demo variable 2 3 var - PowerPoint PPT Presentation

Tern http://ternjs.net 1 // Demo variable 2 3 var audience = "GOTO Berlin"; 4 5 var greeting = "hello " + a 6 7 console.log(greeting); 8 Static scope 1 var aGlobal = 10; 2 3


  1. Tern http://ternjs.net

  2. ​ ​ ​ ​ 1 // Demo variable 2 3 var audience = "GOTO Berlin"; 4 5 var greeting = "hello " + a 6 7 console.log(greeting); 8

  3. ​ ​ Static scope 1 var aGlobal = 10; 2 3 function foo(arg1, arg2) { 4 a 5 } 6

  4. ​ ​ ​ Dynamic types 1 var player = {name: "Heinrich", score: 9999}; 2 3 function foo(x) { 4 x. 5 } 6 7 foo(player); 8

  5. Observation var x = "foo"; // x is a string var y = x; // y is also a string

  6. Observation var x = "foo"; // x is a string OR bool if (quux()) x = false; var y = x; // y is also a string OR bool

  7. Abstract Interpretation

  8. Syntax tree 1 { 2 "type": "Program", 3 "body": [ { ↔ }, 4 { ↔ }, 20 { ↔ } 44 68 ] 69 }

  9. ​ The user is typing 1 var array = []; 2 if (code.isBeing("edited")) { 3 must.know.type.of(array.in 4 orderTo = complete("a", "property"); 5

  10. var x = "foo"; var y = x; x string string y string

  11. var x = "foo"; if (quux()) x = false; var y = x; x string string bool bool y string bool

  12. function f(a, b) { return g(b, a); } function g(x, y) { return x + y; } var r = f("foo", "bar");

  13. function g(x, y) { return x + y; } [+] x y ) → g fn( fn

  14. function f(a, b) { return g(b, a); } function g(x, y) { return x + y; } [+] x y ) → g fn( fn a b ) → f fn( fn'

  15. function f(a, b) { return g(b, a); } function g(x, y) { return x + y; } [+] x y ) → g fn( fn ) → call( a b ) → f fn( fn'

  16. function f(a, b) { return g(b, a); } function g(x, y) { return x + y; } [+] x y ) → g fn( fn ) → call( a b ) → f fn( fn'

  17. [+] x y g ) → fn( fn ) → call( a b f ) → fn( fn' r ) → call( function f(a, b) { return g(b, a); } function g(x, y) { return x + y; } var r = f("foo", "bar");

  18. [+] x y g str ) → fn( str str fn str ) → call( str str a b f str ) → fn( str str fn' r str ) → call( str str str string

  19. var o = {x: 10, y: 0}; .x .y o obj number number obj

  20. var o = {x: 10, y: 0}; var h = o.y; .x .y o obj number number obj get .y h

  21. var o = {x: 10, y: 0}; var h = o.y; .x .y o obj number number obj get .y number h number

  22. Parametric polymorphism function lastOf(array) { return array[array.length - 1]; } var num = lastOf([1, 2, 3]); var str = lastOf(["a", "b", "c"]);

  23. Parametric polymorphism function lastOf(array) { return array[array.length - 1]; } fn( arr ) → get <i>

  24. var __extends = function(child, parent) { for (var key in parent) child[key] = parent[key]; function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); }; Now what?

  25. Missing Connections

  26. Practical Use

  27. ​ ​ ​ ​ ​ ​ 1 // File 1 1 // File 2 2 2 3 var myVar = {x: 1, y: 2}; 3 my 4 4 5 (function(exports) { 6 exports.capitalize = function(word) { 7 return word.charAt(0).toUpperCase() 8 word.slice(1); 9 }; 10 11 exports.garble = function(word) { 12 function garbleCh(ch) { 13 return String.fromCharCode( 14 ch.charCodeAt(0) + 1); 15 } 16 return word.replace(/./g, garbleCh 17 }; 18 }(this.myMod = {})); 19

  28. For Emacs, Vim, & ST ➤ install editor plug-in ➤ add .tern-project file ➤ go

  29. Related Work

  30. Fin. ternjs.net github.com/marijnh/tern marijnhaverbeke.nl twitter.com/marijnjh

  31. eloquentjavascript.net

Recommend


More recommend