Even though the syntax and semantics of Imba is much more related to Ruby than JavaScript, it does compile down to plain performant JavaScript, and is fully compatible with any existing JavaScript library. Imba does not extend any native types from JavaScript. Arrays are arrays, strings are strings, numbers are numbers, classes are constructors with prototypes and so forth. If you simply like Imba better, there is no reason not to write your npm package in Imba, even if it is supposed to be used in the general JavaScript ecosystem. In fact, Imba produces very readable JavaScript, by keeping your indentation, comments, and coding style.
Imba compiles to very straight-forward JavaScript. All the fundamental types are the same as in JavaScript, so for documentation about available methods see MDN Object, Function, String, Number, RegExp, Array, Date, Math.
var single = 'single quotes'
var double = "double quotes"
var interpolation = "string has {double}"
var single = 'single quotes';
var double = "double quotes";
var interpolation = ("string has " + double);
var integer = 42
var float = 42.10
var integer = 42;
var float = 42.10;
var object = {name: 'Imba', type: 'Language'}
var object = {name: 'Imba',type: 'Language'};
var array = [1,2,3,4,5]
var array = [1,2,3,4,5];
var regex = /number is (\d+)/
var regex = /number is (\d+)/;
for num in [1,2,3]
num
for own key, value of object
value
var self = {};
for (let i = 0, items = [1,2,3], len = items.length; i < len; i++) {
items[i];
};
for (let o = self.object(), value, i = 0, keys = Object.keys(o), l = keys.length, key; i < l; i++){
key = keys[i];value = o[key];value;
};
def hello
return 'world'
console.log hello
var self = {};
self.hello = function (){
return 'world';
};
console.log(self.hello());
class Todo
def initialize title
@title = title
@completed = no
def complete
@completed = yes
function Todo(title){
this._title = title;
this._completed = false;
};
Todo.prototype.complete = function (){
return this._completed = true;
};
var item
item = 100 # set value of item
item ||= 100 # set if value is falsy
item &&= 100 # set if value is already truthy
item ?= 100 # set if value is null or undefined
# comparators
item == 10 # check
item === 10 # strictly equal
item != 10 # not equal
item !== item # strictly not equal
item > 10 # greater than
item < 10 # less than
item >= 10 # greater than or equal
item <= 10 # less than or equal
var item;
item = 100; // set value of item
item || (item = 100); // set if value is falsy
item && (item = 100); // set if value is already truthy
(item == null) ? (item = 100) : item; // set if value is null or undefined
// comparators
item == 10; // check
item === 10; // strictly equal
item != 10; // not equal
item !== item; // strictly not equal
item > 10; // greater than
item < 10; // less than
item >= 10; // greater than or equal
item <= 10; // less than or equal
a & b # Bitwise AND
a | b # Bitwise OR
a ^ b # Bitwise XOR
~ a # Bitwise NOT
a << b # Left shift
a >> b # Sign-propagating right shift
a >>> b # Zero-fill right shift
var self = {};
self.a() & self.b(); // Bitwise AND
self.a() | self.b(); // Bitwise OR
self.a() ^ self.b(); // Bitwise XOR
~self.a(); // Bitwise NOT
self.a() << self.b(); // Left shift
self.a() >> self.b(); // Sign-propagating right shift
self.a() >>> self.b(); // Zero-fill right shift