4 ms·
Grok this and you will know everything you need to about spreadsheets: http://jsfiddle.net/ondras/hYfN3/ http://jsfiddle.net/ondras/hYfN3/ You'll probably also
by moron4hire 11y ago
Grok this and you will know everything you need to about spreadsheets: http://jsfiddle.net/ondras/hYfN3/ http://jsfiddle.net/ondras/hYfN3/
You'll probably also end up learning a thing or two about JavaScript. Even now, 2 years after I first saw this, I'm seeing new things in it, and I've been doing JS for 20 years.
- thro1237 11y agoIs there a python/clojure/java version of this?
- moron4hire 11y agoNot that I know of. It exploits some of JavaScript's weird scoping rules to keep everything very short. You're not going to get that in most other languages.
- klibertp 11y agoYou mean this bit: with (DATA) return eval(value.substring(1)); ? It can be implemented in Python without any problems. Of the dynamic languages I know, at least PERL, Python, Ruby, Smalltalk, Lua, Io, Racket have support for something similar. And even if not directly supported, any other language with `eval` would probably be hackable enough to implement this. In TCL that's actually a common idiom. Anyway, I'm not aware of any JS feature which wouldn't be easily replicated in most other dynamic languages. JS was rather unlucky when it comes to language features - its development stalled for years, while in the same time Python, Perl, Ruby, PHP evolved quickly. JS only now gets features implemented in other langs many years ago.
- Trufa 11y agoThis thing is getting me confused, there seems to be some black magic going on, I can't understand how it can possibly work.
- moron4hire 11y agoLook at the calls to defineProperty, then focus on figuring out why the with() block has been used in the `getter` function.
- art-w 11y agoI hope you are joking. This isn't a spreadsheet, it's a stupid bruteforce algorithm that misses the point of the dataflow paradigm: - Everything gets recomputed on any minor change. - If a cell is referenced by N other cells, it will be recomputed N+1 times on every update. Worse, this can be exponential for A2=A1+A1, A3=A2+A2, which leads to A1 being recomputed 5 times. There's no sharing or memoization. - Circular references are detected because they trigger a "too much recursion" exception. - An impure cell "=Math.random()" will be observed with different values by its dependencies.