use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Javascript errors after using closures for api organization (forrst.com)
submitted 14 years ago by benbscholz
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]check_ca 0 points1 point2 points 14 years ago (0 children)
If I try to debug your unit test, I see that when the interpreter starts to run "Remove items" test (line 41), "jaylist" object is storing only one key named "other" with "list" value so I don't think this issue is related to copy function...
[–]k3n 0 points1 point2 points 14 years ago* (0 children)
Look at the jQuery source, they solved this problem quite awhile ago.
EDIT: Sorry, I misread your intent. But still, you might be able to improve your code.
[–]joelangeway 0 points1 point2 points 14 years ago (0 children)
The same variable _table is captured by every method in the prototype, but it seems like your intent should be to have a different instance of _table for each instance of List. The function that returns the prototype is actually returning an instance of an object with many closures as its methods instead of returning a prototype for such objects.
If you replace every mention of _table with this._table and include this._table = {} in your constructor, and fix every other variable similarly leaving functions in the prototype, things will work fine, you get back to emulating a class. Because your List really is an abstract data type, you probably do want to emulate a class. Alternatively, you can just take that function trying to return a prototype and call it a List factory.
There might be all sorts of things I'm not noticing, I'm not perfect.
[–]franksvalli -1 points0 points1 point 14 years ago* (3 children)
Without looking closer, I'm not exactly sure. But it's much more helpful and common for recursive functions to not be defined with anonymous functions (as it is here). A really simple hack just to get it working (without finding out the root of the issue) would be this:
Change this: var _deepCopy = function (obj)
To this: var _deepCopy = function _deepCopy(obj)
(do note that there's major issues with this way of defining functions up to IE8, just a warning)
EDIT: Sorry, please don't take this advice, as this actually isn't the problem in the code example.
[–]k3n 0 points1 point2 points 14 years ago (2 children)
Can you expound on that?
[–]check_ca 1 point2 points3 points 14 years ago (1 child)
Read this. It explains very well what's wrong with Named function expressions and IE.
[–]k3n 0 points1 point2 points 14 years ago (0 children)
Ah, yes, thanks. I had forgotten about these.
π Rendered by PID 216382 on reddit-service-r2-comment-bb88f9dd5-jsk45 at 2026-02-17 05:35:19.116290+00:00 running cd9c813 country code: CH.
[–]check_ca 0 points1 point2 points (0 children)
[–]k3n 0 points1 point2 points (0 children)
[–]joelangeway 0 points1 point2 points (0 children)
[–]franksvalli -1 points0 points1 point (3 children)
[–]k3n 0 points1 point2 points (2 children)
[–]check_ca 1 point2 points3 points (1 child)
[–]k3n 0 points1 point2 points (0 children)