-
Notifications
You must be signed in to change notification settings - Fork 50
JavaScript Backend
brett hartshorn edited this page Aug 9, 2015
·
17 revisions
- a
list
andtuple
are the same type, both are translated into regular javascript arrays. - methods can not be directly passed as callback functions, because in javascript you need to worry about the calling-context-of-this. To properly pass a method as a callback use
bind
like this:F( ob.mymethod.bind(ob) )
whereF
is a function that takes a callback. - dictionary (object) keys are always strings, however the builtin method
mydict.keys()
will return an array of numbers if all the keys are string integers, this allows you to do things likemax( mydict.keys() )
to get the key of the highest number. - class attributes must be accessed using their class names like this
MyClass.somevar
, you can not use this formself.somevar
. - when using external libraries, you must use
new SomeClass()
to create instances. - python is a very type safe language, while javascript is not. In regular python
1+"2"
will raiseTypeError: unsupported operand type(s) for +: 'int' and 'str'
. While in javascript1+"2"
causes no error at all, and instead returns"12"
. The transpiler currently does not check for these types of mistakes, so it is up to you to not make them. As a workaround you can use static typing, and trap type errors when calling functions.
workaround for bad javascript type safety
javascript allows you to create c
which becomes "12"
and is an error,
a runtime error will be raised when c
is passed to somefunc
because it requires an integer.
def somefunc( x:int ):
...
a = 1
b = "2"
c = a + b
somefunc( c )
- https://github.com/rusthon/Rusthon/wiki/WebWorker-Syntax
- https://github.com/rusthon/Rusthon/wiki/Macro-Functions
- https://github.com/rusthon/Rusthon/wiki/JavaScript-Static-Types
- multiple inheritance
- operator overloading (explicit)
- function and class decorators
- getter/setter function decorators
- list comprehensions
- regular and lambda functions
- function calls with *args and **kwargs
- global, nonlocal
- while, for, continue, break
- if, elif, else,
- switch, case
- try, except, raise
- def, lambda
- new, class
- from, import, as
- pass, assert
- and, or, is, in, not
- return, yield
for item in iterable
- NodeList
- FileList
- ClientRectList
- DOMSettableTokenList
- DOMStringList
- DataTransferItemList
- HTMLCollection
- HTMLAllCollection
- SVGElementInstanceList
- SVGNumberList
- SVGTransformList
TODO
- add
- mul
- dir
- type
- hasattr
- getattr
- setattr
- issubclass
- isinstance
- dict
- list
- tuple
- int
- float
- str
- round
- range
- sum
- len
- map
- filter
- min
- max
- abs
- ord
- chr
- open (nodejs only)
- list.append
- list.extend
- list.remove
- list.insert
- list.index
- list.count
- list.pop
- list.len
- list.contains
- list.getitem
- list.setitem
- list.iter
- list.getslice
- set.bisect
- set.difference
- set.intersection
- set.issubset
- str.split
- str.splitlines
- str.strip
- str.startswith
- str.endswith
- str.join
- str.upper
- str.lower
- str.index
- str.find
- str.isdigit
- str.format
- str.getitem
- str.len
- str.getslice
- dict.copy
- dict.clear
- dict.has_key
- dict.update
- dict.items
- dict.keys
- dict.get
- dict.set
- dict.pop
- dict.values
- dict.contains
- dict.iter
- dict.len
- dict.getitem
- dict.setitem