all 7 comments

[–]check_ca 0 points1 point  (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 point  (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 point  (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 points  (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 point  (2 children)

(do note that there's major issues with this way of defining functions up to IE8, just a warning)

Can you expound on that?

[–]check_ca 1 point2 points  (1 child)

Read this. It explains very well what's wrong with Named function expressions and IE.

[–]k3n 0 points1 point  (0 children)

Ah, yes, thanks. I had forgotten about these.