Is there really no way to expose the prototype of a html element in IE (

No, nor is it guaranteed you can fiddle with DOM objects’ prototypes in JavaScript in general. The DOM objects are not part of the ECMAScript spec; they may not be (and traditionally speaking aren’t) native JavaScript Objects at all, in any browser. This is why frameworks tend to have their own ‘container’ wrapper classes. Also … Read more

JavaScript instance functions versus prototype functions [duplicate]

You can actually add another level of privilege via wrapping the whole thing in a self-executing function: var MyObj = (function() { // scoping var privateSharedVar=”foo”; function privateSharedFunction() { // has access to privateSharedVar // may also access publicSharedVar via explicit MyObj.prototype // can’t be called via this } function MyObj() { // constructor var … Read more

Javascript inheritance: call super-constructor or use prototype chain?

The answer to the real question is that you need to do both: Setting the prototype to an instance of the parent initializes the prototype chain (inheritance), this is done only once (since the prototype object is shared). Calling the parent’s constructor initializes the object itself, this is done with every instantiation (you can pass … Read more

What does it mean that Javascript is a prototype based language?

Prototypal inheritance is a form of object-oriented code reuse. Javascript is one of the only [mainstream] object-oriented languages to use prototypal inheritance. Almost all other object-oriented languages are classical. In classical inheritance, the programmer writes a class, which defines an object. Multiple objects can be instantiated from the same class, so you have code in … Read more

Understanding prototypal inheritance in JavaScript

To add to Norbert Hartl’s answer, SuperCar.prototype.constructor isn’t needed, but some people use it as a convenient way of getting the constructing function of an object (SuperCar objects in this case). Just from the first example, Car.call(this, name) is in the SuperCar constructor function because when you do this: var mySuperCar = new SuperCar(“SuperCar”); This … Read more

prototype based vs. class based inheritance

There are about a hundred terminology issues here, mostly built around someone (not you) trying to make their idea sound like The Best. All object oriented languages need to be able to deal with several concepts: encapsulation of data along with associated operations on the data, variously known as data members and member functions, or … Read more

JavaScript: Class.method vs. Class.prototype.method

Yes, the first function has no relationship with an object instance of that constructor function, you can consider it like a ‘static method’. In JavaScript functions are first-class objects, that means you can treat them just like any object, in this case, you are only adding a property to the function object. The second function, … Read more

Benefits of prototypal inheritance over classical?

I know that this answer is 3 years late but I really think the current answers do not provide enough information about how prototypal inheritance is better than classical inheritance. First let’s see the most common arguments JavaScript programmers state in defence of prototypal inheritance (I’m taking these arguments from the current pool of answers): … Read more