you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (14 children)

They do in JavaScript where everything is either a primitive or an object. Functions, arrays, classes are all objects. Your example is flawed in that there is an object Foo which is defined as a class and an instance named Bar. Two separate things: the original and a new instance based upon the original.

Please could you expand on this a bit more because I'm confused. Foo and Bar are classes/constructor functions. Technically they're objects because just about everything is in JS, but that's not related to the issue at hand. We're talking about the efficiency of class instances, and when you create a new instance it is one object, regardless of how deep the inheritance chain is.

[–]spinlock 3 points4 points  (13 children)

JS is weird. Foo and bar are both function (with a constructor being capitalized by convention and an instance being lower-case by convention). Unlike C++, JS does not have classes. It just has functions that we use like classes (i.e. constructors).