In terms of hidden classes, there shouldn't be a difference.

However, since you're setting valueA and valueB in the constructor, setting
them on the prototype too seems entirely pointless to me. The prototype's
values are never visible from instance objects, right? Unless you want to
delete them on some instances, or only set them conditionally in the
constructor, both of which would be bad ideas:

function Foo(a, b) {
  this.valueA = a;
  *if (b > 0) this.valueB = b;  // Bad idea. Always set the same
properties, and in the same order, in your constructors.*
}
Foo.prototype.valueA = 0;  // Harmless, but unnecessary if you avoid the
bad ideas above and below.
Foo.prototype.valueB = 0;  // Harmless, but unnecessary if you avoid the
bad ideas above and below.

var f1 = new Foo(2, -1);
*delete f1.valueA;  // Bad idea. Don't use "delete", ever!*
print(f1.valueA);  // is now 0


On Fri, Jun 6, 2014 at 11:44 PM, Si Robertson <retromodu...@gmail.com>
wrote:

> Quick question for you guys. As far as V8 and its hidden classes are
> concerned, are there any pros or cons of doing the following ...
>
>   function Foo() {
>     this.valueA = 100;
>     this.valueB = 200;
>   }
>
>   Foo.prototype.valueA = 0;
>   Foo.prototype.valueB = 0;
>
> I'm curious if that code will cause any more hidden classes to be created
> than this code ...
>
>   function Foo() {
>     this.valueA = 100;
>     this.valueB = 200;
>   }
>
> Thanks in advance.
>
>  --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to