Can someone help me understand how this works? Don't have deep JS knowledge and I can't see what's going on with `DATA` and all that.
Well I'm a javascript noob myself but I'll try to explain. The clever thing is how he used eval. This is where the magic happens : var getter = function() { var value = localStorage[elm.id] || ""; if (value.charAt(0) == "=") { with (DATA) return eval(value.substring(1)); } else { return isNaN(parseFloat(value)) ? value : parseFloat(value); } }; So if you entered "=A1 + A2" it would be evaluated as DATA[A1]+DATA[A2] .…
A spreadsheet in fewer than 30 lines of JavaScript, no library used
111–120 of 274 posts
Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used
#112Earlier quoted context omitted.
I've felt that way for 16+ years.. of course, 2/3 of that time most developers never took the time to understand/learn JS the language, and then separate that from the horrible browser DOMs in the late 90's. NN's Layers vs IE document.all ... Starting with IE5/6 (and later Phoenix/Firebird/Firefox) it actually got a lot better. It's definitely nothing like IE4/NN4 days, and it looks like IE8 is finally falling off th…
> it looks like IE8 is finally falling off the radar Some are luckier than others... I suspect one of our major clients (one of the country's largest banks) will be stuck using IE8 and nothing but for the next few years at least. They only moved off IE6 recently due to it falling out of support next April, so there is a chance they'll stick with IE8 until 2019 (the year before it and Windows 7 drop out of extended su…
Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used
#113Earlier quoted context omitted.
I'd really love to see one that supports a hierarchy of JSON data, such as a treegrid.
Can you explain how such a tree would map inside a graph? I can't think of an obvious use case.
It would be nice if something like that existed, but with much richer features like the libraries above.
Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used
#114Can someone help me understand how this works? Don't have deep JS knowledge and I can't see what's going on with `DATA` and all that.
Well I'm a javascript noob myself but I'll try to explain. The clever thing is how he used eval. This is where the magic happens : var getter = function() { var value = localStorage[elm.id] || ""; if (value.charAt(0) == "=") { with (DATA) return eval(value.substring(1)); } else { return isNaN(parseFloat(value)) ? value : parseFloat(value); } }; So if you entered "=A1 + A2" it would be evaluated as DATA[A1]+DATA[A2] .…
Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used
#115How does the circular reference prevention work ?
Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used
#116This is truly great as proof of concept and also as a reminder that in software development building 80% of perceived* functionality usually takes only tiny fraction of total development time which is required to build final product. * - this app looks and feels like “almost complete spreadsheet” yet it provides much less than 1% features of even a basic spreadsheet.
The perception of being a "almost complete spreadsheet" might be due to the UI looking similar to older versions of Excel, leading people to assume stuff is there that doesn't.
Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used
#117Earlier quoted context omitted.
Personally I was confused as to how the fellow got around the basics of having to parse tokens until I noticed with (DATA) now that's just genius. I hate writing token parsing.
I'm a bit slow this morning...would anyone mind explaining how that and the defineProperties stuff makes a parse happen?
Consider the formula =A1+A2
inside the getter we have:
with(DATA) eval('A1+A2');
Which is basically the same as: eval('DATA.A1+DATA.A2');
Inside the eval, the getter for A1, and A2 will be called. This will continue until non-formulas are reached and value is returned. The other possibility, is you get an infinite amount of recursion, which causes an error that is caught in the try/catch block. For instance, if you put =A1 in A1, the DATA.A1 getter gets called 1000's of times, eventually causing a stack overflow, which is caught by the try/catch block.Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used
#1182. eval()
3. ???
4. PROFIT! (for the person who stole data/identity, etc)
Re: A spreadsheet in fewer than 30 lines of JavaScript, no library used
#1191. Take user generated content 2. eval() 3. ??? 4. PROFIT! (for the person who stole data/identity, etc)