JS++
JS++ | |
---|---|
Paradigm | Multi-paradigm: Imperative, structured, object-oriented, functional, generic |
Family | ECMAScript |
Designed by | Roger Poon, Anton Rapetov |
Developer | Onux |
First appeared | October 8, 2011 |
Stable release | 0.10.0
/ December 10, 2021 |
Typing discipline | Gradual, static, dynamic |
Scope | lexical |
License | BSD |
Filename extensions | .jspp, .js++, .jpp |
Website | www |
Influenced by | |
C, C++, C#, Java, JavaScript |
JS++ is a programming language for web development that extends JavaScript with a sound type system. It includes imperative, object-oriented, functional, and generic programming features. It is free and open-source software released under a BSD license.
History
JS++ first appeared on October 8, 2011.[1][2][3] The modern implementation was announced at DeveloperWeek 2016[4] and released on May 31, 2016.[5][6][7][8] The language is designed by Roger Poon and Anton Rapetov.
Features
Sound gradual type system
Since JS++ is a superset of JavaScript, declaring data types for variables is optional. However, when types are declared, the types are enforced at both compile time and runtime.
Type annotations in JS++ use the traditional C syntax:
int x = 1;
var y = 2;
bool z = true;
Notably, this differs from TypeScript and ActionScript, which use a more verbose style:
var x : number = 1;
var y : any = 2;
var z : boolean = true;
The type system in JS++ is sound for ECMAScript and DOM API corner cases, including host objects, dynamic key-value pairs, Comet, JScript conditional compilation, dynamic return types, ActiveX, ECMAScript for XML, web browser garbage collector and cyclic reference counting bugs, conditional logic, and other corner cases.[9][10] This differs from other JavaScript supersets where types are optional and discarded at runtime via type erasure, such as in TypeScript.[11][12]
Importing JavaScript libraries
JS++ can use JavaScript libraries using the one-line external
statement as in the following example from the homepage of JS++:
import System;
// Import JavaScript libraries in one line of code
external jQuery, $;
class Example {
public Example() {
// Nearly NO learning curve
// You can keep writing regular JavaScript
var a = 0, random = Math.random();
// Integer types and other primitives
// ... enable fast (optimized) and clear code
byte[] rgbColors = [ 0xFF, 0xFA, 0xFF ];
}
public void showMessage(int id, string text) {
// 100% compatible with regular JavaScript
jQuery("#msgbox").show();
$("#msgbox").text(id.toString() + text);
}
}
Object-oriented programming
While classes in JavaScript (ECMAScript 6) are syntactic sugar for prototypes under the hood,[13] JS++ classes resemble the classes found in classical programming languages such as C++, Java, and C# in terms of memory layout, performance, and semantics. For example, private methods are private at both compile time and runtime, and external JavaScript objects cannot access private JS++ fields or methods.
Example: object-oriented sorting
The following source code illustrates object-oriented sorting in JS++ using the IComparable<T> interface and Comparison enumeration for type-safe and readable comparisons.[14] The custom sorting logic is one line of code in the overridden compare
method below:
import System;
class Employee : IComparable<Employee>
{
private string firstName;
private string lastName;
public Employee(string firstName, string lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public override Comparison compare(Employee that) {
// Sort by employee surname
return this.lastName.compare(that.lastName);
}
public override string toString() {
return this.firstName + " " + this.lastName;
}
}
Employee zig = new Employee("Zig", "Ziglar");
Employee john = new Employee("John", "Smith");
Employee abe = new Employee("Abe", "Lincoln");
Employee[] employees = [ zig, john, abe ];
employees.sort();
Console.log(employees.join(", "));
// Output:
// Abe Lincoln, John Smith, Zig Ziglar
Thus, in the code above, the custom sorting logic provided is:
return this.lastName.compare(that.lastName);
Likewise, to call the sort:
employees.sort();
For printing the sorted results:
Console.log(employees.join(", "));
The join
method will call the overridden toString
method on each individual object, which concatenates the employee's first and last names.
Example: encapsulation by default
JS++ provides encapsulation by default. In the following example, the fields x
and y
are private
by default, even if no access modifier is specified. The methods getX()
and getY()
are public by default. This enables a more concise class definition syntax, as illustrated in the Point
class below:[15]
class Point
{
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
int getX() { return this.x; }
int getY() { return this.y; }
}
Out-of-bounds analysis
JS++ can efficiently analyze out-of-bounds errors at compile time.[16][17][18]
Development tools
Compiler
The JS++ compiler is available for Windows, macOS, and Linux. It is a source-to-source compiler which emits JavaScript source code as an intermediate representation.
Editor integration
JS++ integrates with various code editors including Visual Studio Code, Atom, and Sublime Text.[19][20][21]
Build tools
JS++ can be integrated with third-party build tools like Webpack.[22]
Release history
Version number | Release date | Changes |
---|---|---|
0.01 | 8 October 2011 | Alpha version, initial release |
0.011 | 10 October 2011 | Alpha version |
0.012 | 25 October 2011 | Alpha version |
0.013 | 29 January 2012 | Alpha version |
0.014.1 | 15 August 2012 | Alpha version |
0.4.1 | 31 May 2016 | Beta version, array and callback types, character literals, integral suffixes, removed ECMAScript ASI |
0.4.2 | 18 October 2016 | Modules, function overloading, dead code elimination, editor integrations |
0.4.2.1 | 24 October 2016 | Bug fixes |
0.4.2.2 | 17 November 2016 | Source map debugging |
0.4.2.4 | 25 December 2016 | Support for Mac OS X, C-style casts, callback and array conversions |
0.5.0 | 13 March 2017 | Classes |
0.5.1 | 26 March 2017 | 'foreach' loops |
0.5.2 | 27 July 2017 | BSD License, Interfaces, Abstract Classes, Virtual Methods, Auto-boxing |
0.7.0 | 27 October 2017 | All ECMAScript 3 features via Array<T> and Standard Library |
0.8.0 | 15 March 2018 | Generic programming, Dictionary<T>, multi-line strings, .js++ file extension |
0.8.1 | 27 March 2018 | auto, catch-all clauses, standard library modules for handling time, bug fixes |
0.8.4 | 23 May 2018 | New string functions, advanced generics, bug fixes, standard library expansion |
0.8.5 | 2 June 2018 | Bug fixes |
0.8.10 | 24 November 2018 | Faster compile times, stacks, queues, Unicode, Base64, generic default constraint rules |
0.9.0 | 11 January 2019 | Efficient compile time out-of-bounds error analysis |
0.9.1 | 1 July 2019 | Bug fixes |
0.9.2 | 18 October 2019 | Final (immutable) variables and default to 64-bit for macOS Catalina |
See also
References
- ^ "JavaScript++: New, Powerful Language for Better Web Development". 17 October 2011. Archived from the original on 17 October 2011.
- ^ "C++ et Javascript = Javascript++". La ferme du web. 12 October 2011. Archived from the original on 12 October 2011.
- ^ "Index of /downloads". 18 October 2011. Archived from the original on 18 October 2011.
- ^ "JavaScript Conference - DeveloperWeek 2016 - February 12–18". 13 February 2016. Archived from the original on 13 February 2016.
- ^ Poon, Roger (May 31, 2016). "JS++ Goes Into Public Beta". Onux.com.
- ^ Handy, Alex (June 1, 2016). "Onux seeks to fix JavaScript's lack of type safety". SD Times.
- ^ Krill, Paul (June 6, 2016). "New compiler tackles JavaScript's weak typing". InfoWorld.
- ^ Cimpanu, Catalin (June 9, 2016). "jQuery 3.0 Released and Other JavaScript News". Softpedia.
- ^ "The JS++ Type System, Appendix B: Problems (Why was this hard to solve?)". Retrieved 10 February 2020.
- ^ US patent 10296313, Roger Poon, "Safely consuming dynamically-typed code from a statically-typed programming language", published 2019-05-21
- ^ Bridgwater, Adrian (June 13, 2016). "Onux JS++, an answer to JavaScript 'brittle' type safety?". Computer Weekly. Archived from the original on 2016-07-22.
- ^ "The JS++ Type System". Onux.com.
- ^ "Classes". MDN Web Docs. Retrieved 2025-06-20.
- ^ Poon, Roger (May 28, 2019). "Tips & Tricks: Object-oriented Sorting in JS++ with IComparable<T>". Retrieved June 20, 2025.
- ^ Poon, Roger (June 10, 2018). "Tips & Tricks: Only Fields are 'private' by Default". Retrieved June 20, 2025.
- ^ Díaz, Fabio (January 23, 2019). "JS++, the JavaScript superset, is getting rid of out-of-bounds errors". Akuaroworld.
- ^ Cardoza, Christina (January 16, 2019). "JS++ programming language looks to solve out-of-bounds errors". SD Times.
- ^ Poon, Roger (January 11, 2019). "JS++ 0.9.0: Efficient Compile Time Analysis of Out-of-Bounds Errors". Onux.com.
- ^ "JavaScript superset JS++ adds dead code elimination and more". Computerworld. October 19, 2016.
- ^ Cardoza, Christina (October 19, 2016). "JS++ 0.4.2 released with code editor integrations, modules and dead code elimination". SD Times.
- ^ Clark, Geneva (October 20, 2016). "JS++ 0.4.2 Release - Upgraded With Modular Design, Dead Code Elimination, and Multiple Code Editors". Zeomag.
- ^ Phoenix, Ingwie (7 December 2018). "Proof of Concept: Using JS++ with WebPack". GitHub. Ingwie Phoenix.