2 ms·
That's true in JavaScript - there's an Object.create() method, which creates new object with any other object set as prototype: https://developer.mozilla.org/en
by klibertp 13y ago
That's true in JavaScript - there's an Object.create() method, which creates new object with any other object set as prototype: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
There is a problem with accessing prototypes of objects, as they are not exposed to the user and only available through internal property __prototype__ (IIRC). And there's quite a bit of magic involved with constructor prototypes, which - again - makes it impossible to traverse prototype chain unless you create your objects yourself and store the references yourself.
So yeah, prototypes are nothing special in JS, but their API kind of sucks and could get better. Object.create is a step in the right direction IMO.
- masklinn 13y ago> There is a problem with accessing prototypes of objects, as they are not exposed to the user Actually, Object.getPrototypeOf was added in ECMAScript 5.1. It's even supported by IE9. > only available through internal property __prototype__ (IIRC) It's an external property (the internal one is `[[Prototype]]`_, and is called `__proto__`. It's non-standard, although all modern browsers implement it (even IE11, but not IE10)
- klibertp 13y ago> the internal one is `[[Prototype]]` I was thinking about this one. > Actually, Object.getPrototypeOf was added in ECMAScript 5.1. Wow. Thanks, I wasn't aware of this.