SlideShare a Scribd company logo
1 of 29
Download to read offline
Scala-JS
About me
Evgeniy Safronov
I am from Kherson
Software engineer in RIFL Media LLC
I love to write in JS and talk about JS
contacts:
evgeniy.safronov@outlook.com
skype: lambda.omega1
github.com/javacodegeek
coffeescript, typescript, clojurescript etc.
List of languages that compile to JS
OMG
more than 300
Curious javascript problems
javascript> ["10", "10", "10", "10"].map(parseInt)
[10, NaN, 2, 3]
wtfjs.com
Scala profile
● started in 2001 at the École Polytechnique Fédérale de Lausanne by Martin
Odersky
● functional programming and object oriented programming
● very strong static type system
● was released in 2004 on JVM and .NET
● v2.0 followed in March 2006
www.scala-lang.org
Martin Odersky
invented Scala
co-author Java generics
he wrote a compiler for Java
he wrote a compiler for Scala
www.coursera.org/course/progfun
Companies which choose scala
Elitism Scala
Scala developers are expensive
High barrier to entry
The successful combination of functional and object-oriented paradigms
Wide range of applications
Functional programming with immutable variables, lambdas, closures, lists, and so
on
Java code
public class Person {
private final String firstName;
private final String lastName;
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
}
Scala code
class Person(val firstName: String, val lastName: String)
Back to curious javascript problems
javascript> ["10", "10", "10", "10"].map(parseInt)
[10, NaN, 2, 3]
scala> List("10", "10", "10", "10").map(parseInt)
List(10, 10, 10, 10)
Scala.js developers
1207 commits 702 commits
Code examples: classes
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
fullName() {
return `${this.firstName} ${this.lastName}`;
}
}
ES6
class Person(val firstName: String, val
lastName: String) {
def fullName(): String =
s"$firstName $lastName"
}
Scala.js
Code examples: collections
const personMap = new Map([
[10, new Person("Roger", "Moore")],
[20, new Person("James", "Bond")]
]);
const names = [];
for (const [key, person] of personMap) {
if (key > 15) {
names.push(`${key} = ${person.firstName}`);
}
}
ES6
val personMap = Map(
10 -> new Person("Roger", "Moore"),
20 -> new Person("James", "Bond")
)
val names = for {
(key, person) <- personMap
if key > 15
} yield s"$key = ${person.firstName}"
Scala.js
Compiler output code
object Main extends js.JSApp{
def main() = {
var x = 0
while(x < 10) x += 3
println(x)
// 12
}
}
Scala.js
ScalaJS.c.LMain$.prototype.main__V =
(function() {
var x = 0;
while ((x < 10)) {
x = ((x + 3) | 0)
};
ScalaJS.m.s_Predef$()
.println__O__V(x)
// 12
});
ES5
How to install?
install sbt (scala build tool)
config plugin ”sbt-scalajs”
Rhino presents out of the box, but you can setup V8.
http://www.scala-js.org/tutorial/basic/
HelloApp
package helloapp.webapp
import scala.scalajs.js.JSApp
object HelloApp extends JSApp {
def main(): Unit = {
println("Hello world!")
}
}
Using the DOM
Adding the DOM library to build.sbt
import org.scalajs.dom
import dom.document
def appendPar(targetNode: dom.Node, text: String): Unit = {
val parNode = document.createElement("p")
val textNode = document.createTextNode(text)
parNode.appendChild(textNode)
targetNode.appendChild(parNode)
}
Reacting on User Input
import scala.scalajs.js.annotation.JSExport
@JSExport
def addClickedMessage(): Unit = {
appendPar(document.body, "You clicked the button!")
}
<button id=”click-me-button” type=”button” onClick=”tutorial.webapp.MyApp().
addClickedMessage()”>Click me!</button>
Using jQuery
Adding the DOM library to build.sbt
import org.scalajs.jquery.jQuery
jQuery("body").append("<p>[message]</p>")
Testing
package tutorial.webapp
import utest._
import org.scalajs.jquery.jQuery
object MyTest extends TestSuite {
// Initialize App
HelloApp.setupUI()
def tests = TestSuite {
HelloWorld {
assert(jQuery("p:contains('Hello World')").length == 1)
}
}
}
github.com/lihaoyi/utest
Why you should try Scala.js
New paradigms
All power of Scala
Very good IDE support (IntelliJ Scala and Eclipse ScalaDE)
Scala community
Universal application
expansion of consciousness
Scala.js the official Scala to JavaScript compiler
http://www.scala-js.org/
https://github.com/scala-js/scala-js
https://gitter.im/scala-js/scala-js
Github info:
● 3121 commits
● 41 contributors
● issues 82/1064 open/close
● 36 releases
● 2098 stars
● 188 forks
Benchmarks
Where to use it?
SPA
Enterprise application
Games много кода
?

More Related Content

Similar to Scala js (kyiv js 30-01)

Intro to Scala.js - Scala UG Cologne
Intro to Scala.js - Scala UG CologneIntro to Scala.js - Scala UG Cologne
Intro to Scala.js - Scala UG CologneMarius Soutier
 
An introduction to Scala.js
An introduction to Scala.jsAn introduction to Scala.js
An introduction to Scala.jsKnoldus Inc.
 
Scala.js - yet another what..?
Scala.js - yet another what..?Scala.js - yet another what..?
Scala.js - yet another what..?Artur Skowroński
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingRadoslav Georgiev
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6Solution4Future
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Codemotion
 
Jsonix - Talking to OGC Web Services in JSON
Jsonix - Talking to OGC Web Services in JSONJsonix - Talking to OGC Web Services in JSON
Jsonix - Talking to OGC Web Services in JSONorless
 
Scala.js for large and complex frontend apps
Scala.js for large and complex frontend appsScala.js for large and complex frontend apps
Scala.js for large and complex frontend appsOtto Chrons
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistpmanvi
 
Building a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.jsBuilding a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.jsNicolas Hery
 
ECMAScript.Next ECMAScipt 6
ECMAScript.Next ECMAScipt 6ECMAScript.Next ECMAScipt 6
ECMAScript.Next ECMAScipt 6Kevin DeRudder
 
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)Eugene Yokota
 

Similar to Scala js (kyiv js 30-01) (20)

Intro to Scala.js - Scala UG Cologne
Intro to Scala.js - Scala UG CologneIntro to Scala.js - Scala UG Cologne
Intro to Scala.js - Scala UG Cologne
 
An introduction to Scala.js
An introduction to Scala.jsAn introduction to Scala.js
An introduction to Scala.js
 
Jet presentation
Jet presentationJet presentation
Jet presentation
 
Scala.js - yet another what..?
Scala.js - yet another what..?Scala.js - yet another what..?
Scala.js - yet another what..?
 
Scala.js
Scala.jsScala.js
Scala.js
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft Training
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
 
Full Stack Scala
Full Stack ScalaFull Stack Scala
Full Stack Scala
 
Modern frontend in react.js
Modern frontend in react.jsModern frontend in react.js
Modern frontend in react.js
 
Play framework
Play frameworkPlay framework
Play framework
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
 
Jsonix - Talking to OGC Web Services in JSON
Jsonix - Talking to OGC Web Services in JSONJsonix - Talking to OGC Web Services in JSON
Jsonix - Talking to OGC Web Services in JSON
 
Scala.js for large and complex frontend apps
Scala.js for large and complex frontend appsScala.js for large and complex frontend apps
Scala.js for large and complex frontend apps
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologist
 
Building a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.jsBuilding a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.js
 
ECMAScript.Next ECMAScipt 6
ECMAScript.Next ECMAScipt 6ECMAScript.Next ECMAScipt 6
ECMAScript.Next ECMAScipt 6
 
Es.next
Es.nextEs.next
Es.next
 
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
 

Recently uploaded

Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

Scala js (kyiv js 30-01)

  • 2. About me Evgeniy Safronov I am from Kherson Software engineer in RIFL Media LLC I love to write in JS and talk about JS contacts: evgeniy.safronov@outlook.com skype: lambda.omega1 github.com/javacodegeek
  • 3. coffeescript, typescript, clojurescript etc. List of languages that compile to JS
  • 5. Curious javascript problems javascript> ["10", "10", "10", "10"].map(parseInt) [10, NaN, 2, 3] wtfjs.com
  • 6. Scala profile ● started in 2001 at the École Polytechnique Fédérale de Lausanne by Martin Odersky ● functional programming and object oriented programming ● very strong static type system ● was released in 2004 on JVM and .NET ● v2.0 followed in March 2006 www.scala-lang.org
  • 7. Martin Odersky invented Scala co-author Java generics he wrote a compiler for Java he wrote a compiler for Scala www.coursera.org/course/progfun
  • 9. Elitism Scala Scala developers are expensive High barrier to entry The successful combination of functional and object-oriented paradigms Wide range of applications Functional programming with immutable variables, lambdas, closures, lists, and so on
  • 10. Java code public class Person { private final String firstName; private final String lastName; public Person(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } }
  • 11. Scala code class Person(val firstName: String, val lastName: String)
  • 12. Back to curious javascript problems javascript> ["10", "10", "10", "10"].map(parseInt) [10, NaN, 2, 3] scala> List("10", "10", "10", "10").map(parseInt) List(10, 10, 10, 10)
  • 14. Code examples: classes class Person { constructor(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } fullName() { return `${this.firstName} ${this.lastName}`; } } ES6 class Person(val firstName: String, val lastName: String) { def fullName(): String = s"$firstName $lastName" } Scala.js
  • 15. Code examples: collections const personMap = new Map([ [10, new Person("Roger", "Moore")], [20, new Person("James", "Bond")] ]); const names = []; for (const [key, person] of personMap) { if (key > 15) { names.push(`${key} = ${person.firstName}`); } } ES6 val personMap = Map( 10 -> new Person("Roger", "Moore"), 20 -> new Person("James", "Bond") ) val names = for { (key, person) <- personMap if key > 15 } yield s"$key = ${person.firstName}" Scala.js
  • 16. Compiler output code object Main extends js.JSApp{ def main() = { var x = 0 while(x < 10) x += 3 println(x) // 12 } } Scala.js ScalaJS.c.LMain$.prototype.main__V = (function() { var x = 0; while ((x < 10)) { x = ((x + 3) | 0) }; ScalaJS.m.s_Predef$() .println__O__V(x) // 12 }); ES5
  • 17. How to install? install sbt (scala build tool) config plugin ”sbt-scalajs” Rhino presents out of the box, but you can setup V8. http://www.scala-js.org/tutorial/basic/
  • 18. HelloApp package helloapp.webapp import scala.scalajs.js.JSApp object HelloApp extends JSApp { def main(): Unit = { println("Hello world!") } }
  • 19. Using the DOM Adding the DOM library to build.sbt import org.scalajs.dom import dom.document def appendPar(targetNode: dom.Node, text: String): Unit = { val parNode = document.createElement("p") val textNode = document.createTextNode(text) parNode.appendChild(textNode) targetNode.appendChild(parNode) }
  • 20. Reacting on User Input import scala.scalajs.js.annotation.JSExport @JSExport def addClickedMessage(): Unit = { appendPar(document.body, "You clicked the button!") } <button id=”click-me-button” type=”button” onClick=”tutorial.webapp.MyApp(). addClickedMessage()”>Click me!</button>
  • 21. Using jQuery Adding the DOM library to build.sbt import org.scalajs.jquery.jQuery jQuery("body").append("<p>[message]</p>")
  • 22. Testing package tutorial.webapp import utest._ import org.scalajs.jquery.jQuery object MyTest extends TestSuite { // Initialize App HelloApp.setupUI() def tests = TestSuite { HelloWorld { assert(jQuery("p:contains('Hello World')").length == 1) } } } github.com/lihaoyi/utest
  • 23. Why you should try Scala.js New paradigms All power of Scala Very good IDE support (IntelliJ Scala and Eclipse ScalaDE) Scala community Universal application
  • 25. Scala.js the official Scala to JavaScript compiler http://www.scala-js.org/ https://github.com/scala-js/scala-js https://gitter.im/scala-js/scala-js Github info: ● 3121 commits ● 41 contributors ● issues 82/1064 open/close ● 36 releases ● 2098 stars ● 188 forks
  • 27. Where to use it? SPA Enterprise application Games много кода
  • 28.
  • 29. ?