Table of Contents
TypeScript
PureScript
CoffeeScript
Home Web Front-end JS Tutorial 10 interesting JavaScript scripting languages

10 interesting JavaScript scripting languages

Dec 05, 2017 am 10:35 AM
javascript js language

We all know that JavaScript is not the best language to achieve all tasks. When encountering complex applications, it may not be suitable. To avoid this problem, several new languages ​​and variations of existing languages ​​have been created, all of which generate code that can run in the browser without having to write any JavaScript code or taking into account the limitations of the language.

Dart is a classic object-oriented language in which everything is an object and any object is an instance of a class (objects can also act as functions). It is designed specifically for building applications for browsers, servers, and mobile devices. It is maintained by Google and is the language driving the next generation user interface for AdWords, the most important product that generates revenue for Google, which in itself is a testament to its power at scale.

The language can be translated into JavaScript for use in the browser, or interpreted and executed directly by the Dart VM, which also allows you to build server applications. Mobile apps can be created using the Flutter SDK.

Complex applications also require a mature set of libraries and language features designed specifically for the task, and Dart includes all of them. An example of a popular library is AngularDart, the Dart version of Angular.

It allows you to write type-safe code without being too intrusive; you can write types, but you don't need to because they can be inferred. This allows for creating quick prototypes without having to overthink the details, but once your prototype works you can add types to make it more robust.

Regarding concurrent programming in virtual machines, Dart uses so-called Isolates along with their own memory heaps, instead of shared memory threads (Dart is single-threaded), using messages to implement communication. In the browser, this event is slightly different: instead of creating new isolates, you create new Workers .

// Example extracted from dartlang.org

import 'dart:async';
import 'dart:math' show Random;

main() async {
  print('Compute π using the Monte Carlo method.');
  await for (var estimate in computePi()) {
    print('π ≅ $estimate');
  }
}

/// Generates a stream of increasingly accurate estimates of π.
Stream<double> computePi({int batch: 1000000}) async* {
  var total = 0;
  var count = 0;
  while (true) {
    var points = generateRandom().take(batch);
    var inside = points.where((p) => p.isInsideUnitCircle);
    total += batch;
    count += inside.length;
    var ratio = count / total;
    // Area of a circle is A = π⋅r², therefore π = A/r².
    // So, when given random points with x ∈ <0,1>,
    // y ∈ <0,1>, the ratio of those inside a unit circle
    // should approach π / 4. Therefore, the value of π
    // should be:
    yield ratio * 4;
  }
}

Iterable<Point> generateRandom([int seed]) sync* {
  final random = new Random(seed);
  while (true) {
    yield new Point(random.nextDouble(), random.nextDouble());
  }
}

class Point {
  final double x, y;
  const Point(this.x, this.y);
  bool get isInsideUnitCircle => x * x + y * y <= 1;
}
Copy after login

Getting started with Dart

TypeScript

TypeScript is a superset of JavaScript; a valid JavaScript program is also a valid TypeScript program, but The latter adds static typing. Its compiler can also act as a translator from ES2015+ to the current implementation, so you always get the latest features.

Unlike many other languages, TypeScript keeps the spirit of JavaScript intact and only adds features to make your code more reliable. These are type annotations, along with other type-related features, that make writing JavaScript more enjoyable, thanks to enabling specialized tools like static analyzers to aid in the refactoring process. Additionally, the addition of types improves the interface between different components of the application.

Type inference is supported so you don't have to write all types from the beginning. You can write quick solutions and then add all the types to gain confidence in your code.

TypeScript also supports advanced types such as intersection types, union types, type aliases, discriminated unions, and type guards. You can view all of these types in the Advanced Types page of the TypeScript documentation site.

If you use React, you can also support JSX by adding React types.

class Person {
    private name: string;
    private age: number;
    private salary: number;

    constructor(name: string, age: number, salary: number) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    toString(): string {
        return `${this.name} (${this.age}) (${this.salary})`;
    }
}
Copy after login

Elm is a purely functional programming language that compiles to JS, HTML and CSS. You can build an entire site using just Elm. This makes it a great alternative to JavaScript frameworks like React. Applications built with it automatically use the virtual DOM library, making them very fast. One of its big advantages is the built-in architecture, which makes you forget about data flow and focus on data declaration and logic.

In Elm, all functions are pure, which means they will always return the same output for a given input. They can't do anything else unless you specify it. For example, to access a remote API, you would create a command (command) function to communicate with the outside world, and a subscription (subscription) to listen for responses. Another point of purity is that values ​​are immutable; when you need something, you create new values ​​rather than modify old ones.

Elm adoption can be incremental; ports can be used to communicate with JavaScript and other libraries. Although Elm has not yet reached version 1, it is being used in complex and large applications, making it a viable solution for complex applications.

One of the most attractive features of Elm is the beginner-friendly compiler that, instead of generating hard-to-read messages, generates code that can help you fix your code. If you're learning the language, the compiler itself can be of great help.

module Main exposing (..)

import Html exposing (..)


-- MAIN


main : Program Never Model Msg
main =
    Html.program
        { init = init
        , update = update
        , view = view
        , subscriptions = subscriptions
        }



-- INIT


type alias Model = String


init : ( Model, Cmd Msg )
init = ( "Hello World!", Cmd.none )


-- UPDATE


type Msg
    = DoNothing


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        DoNothing ->
            ( model, Cmd.none )


-- VIEW


view : Model -> Html Msg
view model =
    p [] [text model]


-- SUBSCRIPTIONS


subscriptions : Model -> Sub Msg
subscriptions model =
    Sub.none
Copy after login

Get started with Elm

PureScript

PureScript is a purely functional and strongly typed programming language created by Phil Freeman. It aims to provide strong compatibility with available JavaScript libraries, similar in spirit to Haskell, but keeping the core of JavaScript.

PureScript 的一个强项是它的极简主义。它不包括在其他语言中被认为是必需的功能的任何库。例如,不是编译器本身包含生成器和 promises,而是你可以使用特定的库来完成任务。你可以为所需功能选择想要的实现,这样可以在使用 PureScript 时实现高效和个性化的体验,同时保持生成的代码尽可能小。

其编译器的另一个显著特征就是能够在保持与 JavaScript 的兼容性的同时, 用库和工具生成整洁和可读的代码。

像其他语言一样,PureScript 有自己的构建工具叫做 Pulp,可以与 Gulp 进行比较, 但是用于以这种语言编写的项目。

关于类型系统,与 Elm不同,即另一种 ML 式的语言,PureScript 支持高级类型的功能,如取自 Haskell 的 higher-kinded types(高级类类型) 以及 type classes(类型类), 从而允许创建复杂的抽象。

module Main where

import Prelude
import Data.Foldable (fold)
import TryPureScript

main =
    render $ fold
      [ h1 (text "Try PureScript!")
      , p (text "Try out the examples below, or create your own!")
      , h2 (text "Examples")
      , list (map fromExample examples)
      ]
  where
    fromExample { title, gist } =
      link ("?gist=" <> gist) (text title)

    examples =
      [ { title: "Algebraic Data Types"
        , gist: "37c3c97f47a43f20c548"
        }
      , { title: "Loops"
        , gist: "cfdabdcd085d4ac3dc46"
        }
      , { title: "Operators"
        , gist: "3044550f29a7c5d3d0d0"
        }
      ]
Copy after login

 

开始使用 PureScript

CoffeeScript

CoffeeScript 是一种语言,旨在公开 JavaScript 的良好部分,同时提供更整洁的语法并保留语义。虽然该语言的流行度近年来一直在减弱,但它正在改变方向,现在正在获得一个新的主要版本,为 ES2015+ 的功能提供支持。

你用 CoffeeScript 编写的代码被直接翻译为可读的 JavaScript 代码,并保持与现有库的兼容性。从版本 2 开始,编译器将产生与最新版本的 ECMAScript 兼容的代码。例如,每次你使用一个类,你就获得一个 JavaScript 类。另外,如果你使用 React,也有好消息: JSX 与 CoffeeScript 兼容。

以上内容介绍了10个有趣的语言,这些语言都可以转换成JavaScript代码在浏览器中执行,也可以在Node.js这样的平台上执行。希望能帮助到大家。

相关推荐:

如何用php传递数组给js脚本

JavaScript实现浏览器用户代理检测脚本的方法详解

JavaScript中关于表单脚本的实用技巧

The above is the detailed content of 10 interesting JavaScript scripting languages. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

3 Ways to Change Language on iPhone 3 Ways to Change Language on iPhone Feb 02, 2024 pm 04:12 PM

It's no secret that the iPhone is one of the most user-friendly electronic gadgets, and one of the reasons why is that it can be easily personalized to your liking. In Personalization, you can change the language to a different language than the one you selected when setting up your iPhone. If you're familiar with multiple languages, or your iPhone's language setting is wrong, you can change it as we explain below. How to Change the Language of iPhone [3 Methods] iOS allows users to freely switch the preferred language on iPhone to adapt to different needs. You can change the language of interaction with Siri to facilitate communication with the voice assistant. At the same time, when using the local keyboard, you can easily switch between multiple languages ​​to improve input efficiency.

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ​​and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to set the language of Win10 computer to Chinese? How to set the language of Win10 computer to Chinese? Jan 05, 2024 pm 06:51 PM

Sometimes we just install the computer system and find that the system is in English. In this case, we need to change the computer language to Chinese. So how to change the computer language to Chinese in the win10 system? Now Give you specific operation methods. How to change the computer language in win10 to Chinese 1. Turn on the computer and click the start button in the lower left corner. 2. Click the settings option on the left. 3. Select "Time and Language" on the page that opens. 4. After opening, click "Language" on the left. 5. Here you can set the computer language you want.

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

The relationship between js and vue The relationship between js and vue Mar 11, 2024 pm 05:21 PM

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.

Exploring the boundaries of agents: AgentQuest, a modular benchmark framework for comprehensively measuring and improving the performance of large language model agents Exploring the boundaries of agents: AgentQuest, a modular benchmark framework for comprehensively measuring and improving the performance of large language model agents Apr 11, 2024 pm 08:52 PM

Based on the continuous optimization of large models, LLM agents - these powerful algorithmic entities have shown the potential to solve complex multi-step reasoning tasks. From natural language processing to deep learning, LLM agents are gradually becoming the focus of research and industry. They can not only understand and generate human language, but also formulate strategies, perform tasks in diverse environments, and even use API calls and coding to Build solutions. In this context, the introduction of the AgentQuest framework is a milestone. It not only provides a modular benchmarking platform for the evaluation and advancement of LLM agents, but also provides researchers with a Powerful tools to track and improve the performance of these agents at a more granular level

How to change the language display of vivox60pro vivox60pro system language setting method How to change the language display of vivox60pro vivox60pro system language setting method Mar 23, 2024 am 09:06 AM

1. Click [System Management] in the phone settings menu. 2. Click the [Language] option. 3. Select the system language you want to use.

See all articles