5 ms·
#67 "Prototyped properties affect all objects of the same constructor, simultaneously, even if they already exist" This is only true for properties created as
by praptak 17y ago
#67 "Prototyped properties affect all objects of the same constructor, simultaneously, even if they already exist"
This is only true for properties created as new properties on the existing prototype (Ninja.prototype.swingSword = ...). It is not true if you assign a new object to the prototype (Ninja.prototype = { 'swingSword' : ...}).
The existing objects will only see new properties added to the object which was constructor's prototype at their creation time.
- calambrac 17y agoThis is only true for properties created as new properties on the existing prototype Which is what #67 says. It is not true if you assign a new object to the prototype Which is a completely different thing.
- praptak 17y ago"Which is what #67 says." Nope, it says exactly what I quoted ("prototyped properties"). It also provides an example that happens to be of the later kind (properties set on existing prototype.) "It is not true if you assign a new object to the prototype Which is a completely different thing." Completely different from everything that falls under "prototyped properties"? I disagree. All in all, my point is that if you don't know exactly how it works then there is a chance you might be misled by this #67. I am not arguing that it is "wrong".
- calambrac 17y agoIt says "all objects of the same constructor", which can be losslessly translated to "all objects with the same prototype that were created using JavaScript's retarded way of trying to look kind of like a class-based OO language when really it's not at all". If you change an object's prototype, that object is no longer "of the same constructor". "Ninja.prototype = { 'swingSword' : ...}" is, in fact, a completely different, far more dramatic action than "Ninja.prototype.swingSword = ..." You shouldn't at all have the expectation that the two are anything alike.
- praptak 17y agoIt says "all objects of the same constructor", which can be losslessly translated to "all objects with the same prototype that were created using JavaScript's retarded way of trying to look kind of like a class-based OO language when really it's not at all". It's rather "expanded using knowledge about Javascript object model plus subjective opinion about JS being retarded" than "losslesly translated". Given that said knowledge is the knowledge that the slides are meant to convey, we have some circular reasoning here.
- calambrac 17y agoI didn't say JS was retarded, I said the particular way it tries to look like a class-based OO language even though it isn't was retarded. Given that you were critiquing #67 as though you thought you already understood the information, I felt it was fair game to call you out for being wrong about it. Apologies.
- olavk 17y agoThe terminology is confusing. The property named "prototype" on the constructor is not necessarily the same as the actual prototype object of an instance created with the constructor. There is no standard way to retrieve the prototype object of an instance, but in Mozilla you can get through the non-standard '__proto__' property. The 'prototype' property on the constructor indicates what will be assigned as the prototype of instances created in the future with that constructor. The property can be changed, but that does not affect existing instances created with the constuctor. It would probably be less confusing if the 'prototype' property was called 'assignPrototype' or something like that. The prototype (ie. __proto__ property) of an instance cannot be changed according to the standards (although some non-standard implementations allow that). That is, it cannot be changed to point to a different object, but the prototype object itself is mutable, and when you change it it will affect all instances sharing the prototype. It is not uncommon to think of constructors as equivalent to classes, however technically prototypes and constructors are independent. You can create instances with different prototypes from the same constructor, and you can create instances with the same prototype from different constructors.