Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ujihisa/jinaw
JavaScript in a week
https://github.com/ujihisa/jinaw
Last synced: about 1 month ago
JSON representation
JavaScript in a week
- Host: GitHub
- URL: https://github.com/ujihisa/jinaw
- Owner: ujihisa
- Created: 2013-01-01T01:12:11.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-04-10T07:08:35.000Z (over 11 years ago)
- Last Synced: 2024-05-01T23:19:29.300Z (7 months ago)
- Language: Clojure
- Size: 172 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JavaScript in a week
## Day 1 defining a subset of JavaScript
The implementation should execute the following JavaScript code.
```js
var acc = 'dummy';
var f = function() {
var acc = [];
return function(x) {
return x ? acc.push(x)&&f(x - 1) : acc;
};
console.log("this won't show up!");
}();String.prototype.ujihisa = function() {
var x = 10;
return this + f(x);
}console.log("hello".ujihisa());
console.log(acc == 'dummy');
console.log({'a': 2}.a == 2);
```hello10,9,8,7,6,5,4,3,2,1
trueThat code covers the following important aspects.
* statements and expressions
* literals (String, Number, Function, Array and Object)
* function call, method call, operators, and index/key access of Object
* implicit convertion (String + Number)
* lexical scope (see `acc` var)
* method addition by prototype
* `return` exits from the current functionThe implementation consists of
* parser (JS code to internal representation in S-expression)
* runtimeI'll work on runtime first in Clojure, then work on parser in Haskell with parsec.
### parsing
I don't implement the parser for now but I simply parse the sample code by hand. the first 2 statements will be like the below.
before:
```js
var acc = 'dummy';
var f = function() {
var acc = [];
return function(x) {
return x ? acc.push(x)&&f(x - 1) : acc;
};
}();
```after:
```clojure
'[(var 'acc "dummy")
(var 'f
(call
(function []
[[(var 'acc (array))
(return
(function ['x]
[[(return (if 'x
(and (mcall 'push 'acc ['x])
(call 'f [(minus 'x 1)]))
'acc))]]))]])
[]))]
```## What doesn't this implementation cover
* try/catch
* lots of standard classes (e.g. Date)
* browser specific features
* setTimeout
* require (like node.js's)