Scala.js
source link: http://www.scala-js.org/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Scala.js
1.3.1
A safer way to build robust
front-end web applications!
Correctness
Performance
Interoperability
Excellent editor support
With Scala.js, typos and type-errors are immediately caught and shown to you in your editor, without even needing to compile your code. Refactor any field or method with ease, with the confidence that if you mess it up the editor will tell you immediately. Stop flipping back and forth between your editor and MDN, because your editor will display what methods are available, what arguments they take, what they return, and even their documentation, right in-line with your code!
Go beyond JavaScript ES6, today
Hello World!
console.log("Hello World!");
println("Hello World!")
Classes
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
fullName() {
return `${this.firstName} ${this.lastName}`;
}
}
class Person(val firstName: String, val lastName: String) {
def fullName(): String =
s"$firstName $lastName"
}
Fat arrow functions
const names = persons.map(p => p.firstName);
val names = persons.map(p => p.firstName)
// or an even shorter version
val names = persons.map(_.firstName)
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}`);
}
}
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}"
To find out more about what Scala.js looks like for JavaScript developers, check out the detailed comparisons. If you want to try it out yourself, check out the Tutorials!
Feature JavaScript ES5 JavaScript ES6 TypeScript Scala.js Interoperability Fully EcmaScript5 compatible No compilation required Use existing JS libraries Language features Classes Modules Support for types Strong type system Extensive standard libraries Optimizing compiler Macros, to extend the language IDE support Catch most errors in IDE Easy and reliable refactoring Reliable code completionRecommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK